<?php namespace {function C($name=null, $value=null,$default=null) { static $_config = array(); if (empty($name)) { return $_config; } if (is_string($name)) { if (!strpos($name, '.')) { $name = strtoupper($name); if (is_null($value)) return isset($_config[$name]) ? $_config[$name] : $default; $_config[$name] = $value; return null; } $name = explode('.', $name); $name[0] = strtoupper($name[0]); if (is_null($value)) return isset($_config[$name[0]][$name[1]]) ? $_config[$name[0]][$name[1]] : $default; $_config[$name[0]][$name[1]] = $value; return null; } if (is_array($name)){ $_config = array_merge($_config, array_change_key_case($name,CASE_UPPER)); return null; } return null; } function load_config($file,$parse=CONF_PARSE){ $ext = pathinfo($file,PATHINFO_EXTENSION); switch($ext){ case 'php': return include $file; case 'ini': return parse_ini_file($file); case 'yaml': return yaml_parse_file($file); case 'xml': return (array)simplexml_load_file($file); case 'json': return json_decode(file_get_contents($file), true); default: if(function_exists($parse)){ return $parse($file); }else{ E(L('_NOT_SUPPORT_').':'.$ext); } } } if (!function_exists('yaml_parse_file')) { function yaml_parse_file($file) { vendor('spyc.Spyc'); return Spyc::YAMLLoad($file); } } function E($msg, $code=0) { throw new Think\Exception($msg, $code); } function G($start,$end='',$dec=4) { static $_info = array(); static $_mem = array(); if(is_float($end)) { $_info[$start] = $end; }elseif(!empty($end)){ if(!isset($_info[$end])) $_info[$end] = microtime(TRUE); if(MEMORY_LIMIT_ON && $dec=='m'){ if(!isset($_mem[$end])) $_mem[$end] = memory_get_usage(); return number_format(($_mem[$end]-$_mem[$start])/1024); }else{ return number_format(($_info[$end]-$_info[$start]),$dec); } }else{ $_info[$start] = microtime(TRUE); if(MEMORY_LIMIT_ON) $_mem[$start] = memory_get_usage(); } return null; } function L($name=null, $value=null) { static $_lang = array(); if (empty($name)) return $_lang; if (is_string($name)) { $name = strtoupper($name); if (is_null($value)){ return isset($_lang[$name]) ? $_lang[$name] : $name; }elseif(is_array($value)){ $replace = array_keys($value); foreach($replace as &$v){ $v = '{$'.$v.'}'; } return str_replace($replace,$value,isset($_lang[$name]) ? $_lang[$name] : $name); } $_lang[$name] = $value; return null; } if (is_array($name)) $_lang = array_merge($_lang, array_change_key_case($name, CASE_UPPER)); return null; } function trace($value='[think]',$label='',$level='DEBUG',$record=false) { return Think\Think::trace($value,$label,$level,$record); } function compile($filename) { $content = php_strip_whitespace($filename); $content = trim(substr($content, 5)); $content = preg_replace('/\/\/\[RUNTIME\](.*?)\/\/\[\/RUNTIME\]/s', '', $content); if(0===strpos($content,'namespace')){ $content = preg_replace('/namespace\s(.*?);/','namespace \\1{',$content,1); }else{ $content = 'namespace {'.$content; } if ('?>' == substr($content, -2)) $content = substr($content, 0, -2); return $content.'}'; } function T($template='',$layer=''){ if(false === strpos($template,'://')){ $template = 'http://'.str_replace(':', '/',$template); } $info = parse_url($template); $file = $info['host'].(isset($info['path'])?$info['path']:''); $module = isset($info['user'])?$info['user'].'/':MODULE_NAME.'/'; $extend = $info['scheme']; $layer = $layer?$layer:C('DEFAULT_V_LAYER'); $auto = C('AUTOLOAD_NAMESPACE'); if($auto && isset($auto[$extend])){ $baseUrl = $auto[$extend].$module.$layer.'/'; }elseif(C('VIEW_PATH')){ $baseUrl = C('VIEW_PATH'); }elseif(defined('TMPL_PATH')){ $baseUrl = TMPL_PATH.$module; }else{ $baseUrl = APP_PATH.$module.$layer.'/'; } $theme = substr_count($file,'/')<2 ? C('DEFAULT_THEME') : ''; $depr = C('TMPL_FILE_DEPR'); if('' == $file) { $file = CONTROLLER_NAME . $depr . ACTION_NAME; }elseif(false === strpos($file, '/')){ $file = CONTROLLER_NAME . $depr . $file; }elseif('/' != $depr){ $file = substr_count($file,'/')>1 ? substr_replace($file,$depr,strrpos($file,'/'),1) : str_replace('/', $depr, $file); } return $baseUrl.($theme?$theme.'/':'').$file.C('TMPL_TEMPLATE_SUFFIX'); } function I($name,$default='',$filter=null,$datas=null) { static $_PUT = null; if(strpos($name,'/')){ list($name,$type) = explode('/',$name,2); }elseif(C('VAR_AUTO_STRING')){ $type = 's'; } if(strpos($name,'.')) { list($method,$name) = explode('.',$name,2); }else{ $method = 'param'; } switch(strtolower($method)) { case 'get' : $input =& $_GET; break; case 'post' : $input =& $_POST; break; case 'put' : if(is_null($_PUT)){ parse_str(file_get_contents('php://input'), $_PUT); } $input = $_PUT; break; case 'param' : switch($_SERVER['REQUEST_METHOD']) { case 'POST': $input = $_POST; break; case 'PUT': if(is_null($_PUT)){ parse_str(file_get_contents('php://input'), $_PUT); } $input = $_PUT; break; default: $input = $_GET; } break; case 'path' : $input = array(); if(!empty($_SERVER['PATH_INFO'])){ $depr = C('URL_PATHINFO_DEPR'); $input = explode($depr,trim($_SERVER['PATH_INFO'],$depr)); } break; case 'request' : $input =& $_REQUEST; break; case 'session' : $input =& $_SESSION; break; case 'cookie' : $input =& $_COOKIE; break; case 'server' : $input =& $_SERVER; break; case 'globals' : $input =& $GLOBALS; break; case 'data' : $input =& $datas; break; default: return null; } if(''==$name) { $data = $input; $filters = isset($filter)?$filter:C('DEFAULT_FILTER'); if($filters) { if(is_string($filters)){ $filters = explode(',',$filters); } foreach($filters as $filter){ $data = array_map_recursive($filter,$data); } } }elseif(isset($input[$name])) { $data = $input[$name]; $filters = isset($filter)?$filter:C('DEFAULT_FILTER'); if($filters) { if(is_string($filters)){ if(0 === strpos($filters,'/')){ if(1 !== preg_match($filters,(string)$data)){ return isset($default) ? $default : null; } }else{ $filters = explode(',',$filters); } }elseif(is_int($filters)){ $filters = array($filters); } if(is_array($filters)){ foreach($filters as $filter){ if(function_exists($filter)) { $data = is_array($data) ? array_map_recursive($filter,$data) : $filter($data); }else{ $data = filter_var($data,is_int($filter) ? $filter : filter_id($filter)); if(false === $data) { return isset($default) ? $default : null; } } } } } if(!empty($type)){ switch(strtolower($type)){ case 'a': $data = (array)$data; break; case 'd': $data = (int)$data; break; case 'f': $data = (float)$data; break; case 'b': $data = (boolean)$data; break; case 's': default: $data = (string)$data; } } }else{ $data = isset($default)?$default:null; } is_array($data) && array_walk_recursive($data,'think_filter'); return $data; } function array_map_recursive($filter, $data) { $result = array(); foreach ($data as $key => $val) { $result[$key] = is_array($val) ? array_map_recursive($filter, $val) : call_user_func($filter, $val); } return $result; } function N($key, $step=0,$save=false) { static $_num = array(); if (!isset($_num[$key])) { $_num[$key] = (false !== $save)? S('N_'.$key) : 0; } if (empty($step)){ return $_num[$key]; }else{ $_num[$key] = $_num[$key] + (int)$step; } if(false !== $save){ S('N_'.$key,$_num[$key],$save); } return null; } function parse_name($name, $type=0) { if ($type) { return ucfirst(preg_replace_callback('/_([a-zA-Z])/', function($match){return strtoupper($match[1]);}, $name)); } else { return strtolower(trim(preg_replace("/[A-Z]/", "_\\0", $name), "_")); } } function require_cache($filename) { static $_importFiles = array(); if (!isset($_importFiles[$filename])) { if (file_exists_case($filename)) { require $filename; $_importFiles[$filename] = true; } else { $_importFiles[$filename] = false; } } return $_importFiles[$filename]; } function file_exists_case($filename) { if (is_file($filename)) { if (IS_WIN && APP_DEBUG) { if (basename(realpath($filename)) != basename($filename)) return false; } return true; } return false; } function import($class, $baseUrl = '', $ext=EXT) { static $_file = array(); $class = str_replace(array('.', '#'), array('/', '.'), $class); if (isset($_file[$class . $baseUrl])) return true; else $_file[$class . $baseUrl] = true; $class_strut = explode('/', $class); if (empty($baseUrl)) { if ('@' == $class_strut[0] || MODULE_NAME == $class_strut[0]) { $baseUrl = MODULE_PATH; $class = substr_replace($class, '', 0, strlen($class_strut[0]) + 1); }elseif ('Common' == $class_strut[0]) { $baseUrl = COMMON_PATH; $class = substr($class, 7); }elseif (in_array($class_strut[0],array('Think','Org','Behavior','Com','Vendor')) || is_dir(LIB_PATH.$class_strut[0])) { $baseUrl = LIB_PATH; }else { $baseUrl = APP_PATH; } } if (substr($baseUrl, -1) != '/') $baseUrl .= '/'; $classfile = $baseUrl . $class . $ext; if (!class_exists(basename($class),false)) { return require_cache($classfile); } return null; } function load($name, $baseUrl='', $ext='.php') { $name = str_replace(array('.', '#'), array('/', '.'), $name); if (empty($baseUrl)) { if (0 === strpos($name, '@/')) { $baseUrl = MODULE_PATH.'Common/'; $name = substr($name, 2); } else { $array = explode('/', $name); $baseUrl = APP_PATH . array_shift($array).'/Common/'; $name = implode('/',$array); } } if (substr($baseUrl, -1) != '/') $baseUrl .= '/'; require_cache($baseUrl . $name . $ext); } function vendor($class, $baseUrl = '', $ext='.php') { if (empty($baseUrl)) $baseUrl = VENDOR_PATH; return import($class, $baseUrl, $ext); } function D($name='',$layer='') { if(empty($name)) return new Think\Model; static $_model = array(); $layer = $layer? : C('DEFAULT_M_LAYER'); if(isset($_model[$name.$layer])) return $_model[$name.$layer]; $class = parse_res_name($name,$layer); if(class_exists($class)) { $model = new $class(basename($name)); }elseif(false === strpos($name,'/')){ if(!C('APP_USE_NAMESPACE')){ import('Common/'.$layer.'/'.$class); }else{ $class = '\\Common\\'.$layer.'\\'.$name.$layer; } $model = class_exists($class)? new $class($name) : new Think\Model($name); }else { Think\Log::record('D方法实例化没找到模型类'.$class,Think\Log::NOTICE); $model = new Think\Model(basename($name)); } $_model[$name.$layer] = $model; return $model; } function M($name='', $tablePrefix='',$connection='') { static $_model = array(); if(strpos($name,':')) { list($class,$name) = explode(':',$name); }else{ $class = 'Think\\Model'; } $guid = (is_array($connection)?implode('',$connection):$connection).$tablePrefix . $name . '_' . $class; if (!isset($_model[$guid])) $_model[$guid] = new $class($name,$tablePrefix,$connection); return $_model[$guid]; } function parse_res_name($name,$layer,$level=1){ if(strpos($name,'://')) { list($extend,$name) = explode('://',$name); }else{ $extend = ''; } if(strpos($name,'/') && substr_count($name, '/')>=$level){ list($module,$name) = explode('/',$name,2); }else{ $module = defined('MODULE_NAME') ? MODULE_NAME : '' ; } $array = explode('/',$name); if(!C('APP_USE_NAMESPACE')){ $class = parse_name($name, 1); import($module.'/'.$layer.'/'.$class.$layer); }else{ $class = $module.'\\'.$layer; foreach($array as $name){ $class .= '\\'.parse_name($name, 1); } if($extend){ $class = $extend.'\\'.$class; } } return $class.$layer; } function controller($name,$path=''){ $layer = C('DEFAULT_C_LAYER'); if(!C('APP_USE_NAMESPACE')){ $class = parse_name($name, 1).$layer; import(MODULE_NAME.'/'.$layer.'/'.$class); }else{ $class = ( $path ? basename(ADDON_PATH).'\\'.$path : MODULE_NAME ).'\\'.$layer; $array = explode('/',$name); foreach($array as $name){ $class .= '\\'.parse_name($name, 1); } $class .= $layer; } if(class_exists($class)) { return new $class(); }else { return false; } } function A($name,$layer='',$level=0) { static $_action = array(); $layer = $layer? : C('DEFAULT_C_LAYER'); $level = $level? : ($layer == C('DEFAULT_C_LAYER')?C('CONTROLLER_LEVEL'):1); if(isset($_action[$name.$layer])) return $_action[$name.$layer]; $class = parse_res_name($name,$layer,$level); if(class_exists($class)) { $action = new $class(); $_action[$name.$layer] = $action; return $action; }else { return false; } } function R($url,$vars=array(),$layer='') { $info = pathinfo($url); $action = $info['basename']; $module = $info['dirname']; $class = A($module,$layer); if($class){ if(is_string($vars)) { parse_str($vars,$vars); } return call_user_func_array(array(&$class,$action.C('ACTION_SUFFIX')),$vars); }else{ return false; } } function tag($tag, &$params=NULL) { \Think\Hook::listen($tag,$params); } function B($name, $tag='',&$params=NULL) { if(''==$tag){ $name .= 'Behavior'; } return \Think\Hook::exec($name,$tag,$params); } function strip_whitespace($content) { $stripStr = ''; $tokens = token_get_all($content); $last_space = false; for ($i = 0, $j = count($tokens); $i < $j; $i++) { if (is_string($tokens[$i])) { $last_space = false; $stripStr .= $tokens[$i]; } else { switch ($tokens[$i][0]) { case T_COMMENT: case T_DOC_COMMENT: break; case T_WHITESPACE: if (!$last_space) { $stripStr .= ' '; $last_space = true; } break; case T_START_HEREDOC: $stripStr .= "<<<THINK\n"; break; case T_END_HEREDOC: $stripStr .= "THINK;\n"; for($k = $i+1; $k < $j; $k++) { if(is_string($tokens[$k]) && $tokens[$k] == ';') { $i = $k; break; } else if($tokens[$k][0] == T_CLOSE_TAG) { break; } } break; default: $last_space = false; $stripStr .= $tokens[$i][1]; } } } return $stripStr; } function throw_exception($msg, $type='Think\\Exception', $code=0) { Think\Log::record('建议使用E方法替代throw_exception',Think\Log::NOTICE); if (class_exists($type, false)) throw new $type($msg, $code); else Think\Think::halt($msg); } function dump($var, $echo=true, $label=null, $strict=true) { $label = ($label === null) ? '' : rtrim($label) . ' '; if (!$strict) { if (ini_get('html_errors')) { $output = print_r($var, true); $output = '<pre>' . $label . htmlspecialchars($output, ENT_QUOTES) . '</pre>'; } else { $output = $label . print_r($var, true); } } else { ob_start(); var_dump($var); $output = ob_get_clean(); if (!extension_loaded('xdebug')) { $output = preg_replace('/\]\=\>\n(\s+)/m', '] => ', $output); $output = '<pre>' . $label . htmlspecialchars($output, ENT_QUOTES) . '</pre>'; } } if ($echo) { echo($output); return null; }else return $output; } function layout($layout) { if(false !== $layout) { C('LAYOUT_ON',true); if(is_string($layout)) { C('LAYOUT_NAME',$layout); } }else{ C('LAYOUT_ON',false); } } function U($url='',$vars='',$suffix=true,$domain=false) { $info = parse_url($url); $url = !empty($info['path'])?$info['path']:ACTION_NAME; if(isset($info['fragment'])) { $anchor = $info['fragment']; if(false !== strpos($anchor,'?')) { list($anchor,$info['query']) = explode('?',$anchor,2); } if(false !== strpos($anchor,'@')) { list($anchor,$host) = explode('@',$anchor, 2); } }elseif(false !== strpos($url,'@')) { list($url,$host) = explode('@',$info['path'], 2); } if(isset($host)) { $domain = $host.(strpos($host,'.')?'':strstr($_SERVER['HTTP_HOST'],'.')); }elseif($domain===true){ $domain = $_SERVER['HTTP_HOST']; if(C('APP_SUB_DOMAIN_DEPLOY') ) { $domain = $domain=='localhost'?'localhost':'www'.strstr($_SERVER['HTTP_HOST'],'.'); foreach (C('APP_SUB_DOMAIN_RULES') as $key => $rule) { $rule = is_array($rule)?$rule[0]:$rule; if(false === strpos($key,'*') && 0=== strpos($url,$rule)) { $domain = $key.strstr($domain,'.'); $url = substr_replace($url,'',0,strlen($rule)); break; } } } } if(is_string($vars)) { parse_str($vars,$vars); }elseif(!is_array($vars)){ $vars = array(); } if(isset($info['query'])) { parse_str($info['query'],$params); $vars = array_merge($params,$vars); } $depr = C('URL_PATHINFO_DEPR'); $urlCase = C('URL_CASE_INSENSITIVE'); if($url) { if(0=== strpos($url,'/')) { $route = true; $url = substr($url,1); if('/' != $depr) { $url = str_replace('/',$depr,$url); } }else{ if('/' != $depr) { $url = str_replace('/',$depr,$url); } $url = trim($url,$depr); $path = explode($depr,$url); $var = array(); $varModule = C('VAR_MODULE'); $varController = C('VAR_CONTROLLER'); $varAction = C('VAR_ACTION'); $var[$varAction] = !empty($path)?array_pop($path):ACTION_NAME; $var[$varController] = !empty($path)?array_pop($path):CONTROLLER_NAME; if($maps = C('URL_ACTION_MAP')) { if(isset($maps[strtolower($var[$varController])])) { $maps = $maps[strtolower($var[$varController])]; if($action = array_search(strtolower($var[$varAction]),$maps)){ $var[$varAction] = $action; } } } if($maps = C('URL_CONTROLLER_MAP')) { if($controller = array_search(strtolower($var[$varController]),$maps)){ $var[$varController] = $controller; } } if($urlCase) { $var[$varController] = parse_name($var[$varController]); } $module = ''; if(!empty($path)) { $var[$varModule] = implode($depr,$path); }else{ if(C('MULTI_MODULE')) { if(MODULE_NAME != C('DEFAULT_MODULE') || !C('MODULE_ALLOW_LIST')){ $var[$varModule]= MODULE_NAME; } } } if($maps = C('URL_MODULE_MAP')) { if($_module = array_search(strtolower($var[$varModule]),$maps)){ $var[$varModule] = $_module; } } if(isset($var[$varModule])){ $module = $var[$varModule]; unset($var[$varModule]); } } } if(C('URL_MODEL') == 0) { $url = __APP__.'?'.C('VAR_MODULE')."={$module}&".http_build_query(array_reverse($var)); if($urlCase){ $url = strtolower($url); } if(!empty($vars)) { $vars = http_build_query($vars); $url .= '&'.$vars; } }else{ if(isset($route)) { $url = __APP__.'/'.rtrim($url,$depr); }else{ $module = (defined('BIND_MODULE') && BIND_MODULE==$module )? '' : $module; $url = __APP__.'/'.($module?$module.MODULE_PATHINFO_DEPR:'').implode($depr,array_reverse($var)); } if($urlCase){ $url = strtolower($url); } if(!empty($vars)) { $s = array(); foreach ($vars as $var => $val){ if(is_array($val)){ foreach($val as $k => $v){ $s[$var . '[' . $k . ']'] = $v; } }else{ if('' !== trim($val)){ $url .= $depr . $var . $depr . urlencode($val); } } } if($s){ $url .= '?' . http_build_query($s); } } if($suffix) { $suffix = $suffix===true?C('URL_HTML_SUFFIX'):$suffix; if($pos = strpos($suffix, '|')){ $suffix = substr($suffix, 0, $pos); } if($suffix && '/' != substr($url,-1)){ $url .= '.'.ltrim($suffix,'.'); } } } if(isset($anchor)){ $url .= '#'.$anchor; } if($domain) { $url = (is_ssl()?'https://':'http://').$domain.$url; } return $url; } function W($name, $data=array()) { return R($name,$data,'Widget'); } function is_ssl() { if(isset($_SERVER['HTTPS']) && ('1' == $_SERVER['HTTPS'] || 'on' == strtolower($_SERVER['HTTPS']))){ return true; }elseif(isset($_SERVER['SERVER_PORT']) && ('443' == $_SERVER['SERVER_PORT'] )) { return true; } return false; } function redirect($url, $time=0, $msg='') { $url = str_replace(array("\n", "\r"), '', $url); if (empty($msg)) $msg = "系统将在{$time}秒之后自动跳转到{$url}！"; if (!headers_sent()) { if (0 === $time) { header('Location: ' . $url); } else { header("refresh:{$time};url={$url}"); echo($msg); } exit(); } else { $str = "<meta http-equiv='Refresh' content='{$time};URL={$url}'>"; if ($time != 0) $str .= $msg; exit($str); } } function S($name,$value='',$options=null) { static $cache = ''; if(is_array($options)){ $type = isset($options['type'])?$options['type']:''; $cache = Think\Cache::getInstance($type,$options); }elseif(is_array($name)) { $type = isset($name['type'])?$name['type']:''; $cache = Think\Cache::getInstance($type,$name); return $cache; }elseif(empty($cache)) { $cache = Think\Cache::getInstance(); } if(''=== $value){ return $cache->get($name); }elseif(is_null($value)) { return $cache->rm($name); }else { if(is_array($options)) { $expire = isset($options['expire'])?$options['expire']:NULL; }else{ $expire = is_numeric($options)?$options:NULL; } return $cache->set($name, $value, $expire); } } function F($name, $value='', $path=DATA_PATH) { static $_cache = array(); $filename = $path . $name . '.php'; if ('' !== $value) { if (is_null($value)) { if(false !== strpos($name,'*')){ return false; }else{ unset($_cache[$name]); return Think\Storage::unlink($filename,'F'); } } else { Think\Storage::put($filename,serialize($value),'F'); $_cache[$name] = $value; return null; } } if (isset($_cache[$name])) return $_cache[$name]; if (Think\Storage::has($filename,'F')){ $value = unserialize(Think\Storage::read($filename,'F')); $_cache[$name] = $value; } else { $value = false; } return $value; } function to_guid_string($mix) { if (is_object($mix)) { return spl_object_hash($mix); } elseif (is_resource($mix)) { $mix = get_resource_type($mix) . strval($mix); } else { $mix = serialize($mix); } return md5($mix); } function xml_encode($data, $root='think', $item='item', $attr='', $id='id', $encoding='utf-8') { if(is_array($attr)){ $_attr = array(); foreach ($attr as $key => $value) { $_attr[] = "{$key}=\"{$value}\""; } $attr = implode(' ', $_attr); } $attr = trim($attr); $attr = empty($attr) ? '' : " {$attr}"; $xml = "<?xml version=\"1.0\" encoding=\"{$encoding}\"?>"; $xml .= "<{$root}{$attr}>"; $xml .= data_to_xml($data, $item, $id); $xml .= "</{$root}>"; return $xml; } function data_to_xml($data, $item='item', $id='id') { $xml = $attr = ''; foreach ($data as $key => $val) { if(is_numeric($key)){ $id && $attr = " {$id}=\"{$key}\""; $key = $item; } $xml .= "<{$key}{$attr}>"; $xml .= (is_array($val) || is_object($val)) ? data_to_xml($val, $item, $id) : $val; $xml .= "</{$key}>"; } return $xml; } function session($name='',$value='') { $prefix = C('SESSION_PREFIX'); if(is_array($name)) { if(isset($name['prefix'])) { C('SESSION_PREFIX',$name['prefix']); } if(C('VAR_SESSION_ID') && isset($_REQUEST[C('VAR_SESSION_ID')])) { session_id($_REQUEST[C('VAR_SESSION_ID')]); } else if(isset($name['id'])) { session_id($name['id']); } if('common' == APP_MODE) { ini_set('session.auto_start', 0); } if(isset($name['name'])) { session_name($name['name']); } if(isset($name['path'])) { session_save_path($name['path']); } if(isset($name['domain'])) { ini_set('session.cookie_domain', $name['domain']); } if(isset($name['expire'])) { ini_set('session.gc_maxlifetime', $name['expire']); ini_set('session.cookie_lifetime', $name['expire']); } if(isset($name['use_trans_sid'])) { ini_set('session.use_trans_sid', $name['use_trans_sid']?1:0); } if(isset($name['use_cookies'])) { ini_set('session.use_cookies', $name['use_cookies']?1:0); } if(isset($name['use_only_cookies'])) { ini_set('session.use_only_cookies', $name['use_only_cookies'] ? 1:0); } if(isset($name['cache_limiter'])) { session_cache_limiter($name['cache_limiter']); } if(isset($name['cache_expire'])) { session_cache_expire($name['cache_expire']); } if(isset($name['type'])) { C('SESSION_TYPE',$name['type']); } if(C('SESSION_TYPE')) { $type = C('SESSION_TYPE'); $class = strpos($type,'\\')? $type : 'Think\\Session\\Driver\\'. ucwords(strtolower($type)); $hander = new $class(); session_set_save_handler( array(&$hander,"open"), array(&$hander,"close"), array(&$hander,"read"), array(&$hander,"write"), array(&$hander,"destroy"), array(&$hander,"gc") ); } if(C('SESSION_AUTO_START')) { session_start(); } } else if('' === $value) { if(''===$name) { return $prefix ? $_SESSION[$prefix] : $_SESSION; } else if(0===strpos($name,'[')) { if('[pause]'==$name) { session_write_close(); } else if('[start]'==$name) { session_start(); } else if('[destroy]'==$name) { $_SESSION = array(); session_unset(); session_destroy(); } else if('[regenerate]'==$name) { session_regenerate_id(); } } else if(0===strpos($name,'?')) { $name = substr($name,1); if(strpos($name,'.')) { list($name1,$name2) = explode('.',$name); return $prefix ? isset($_SESSION[$prefix][$name1][$name2]):isset($_SESSION[$name1][$name2]); } else { return $prefix?isset($_SESSION[$prefix][$name]):isset($_SESSION[$name]); } } else if(is_null($name)) { if($prefix) { unset($_SESSION[$prefix]); } else { $_SESSION = array(); } } else if($prefix) { if(strpos($name,'.')) { list($name1,$name2) = explode('.',$name); return isset($_SESSION[$prefix][$name1][$name2])?$_SESSION[$prefix][$name1][$name2]:null; } else { return isset($_SESSION[$prefix][$name])?$_SESSION[$prefix][$name]:null; } } else { if(strpos($name,'.')) { list($name1,$name2) = explode('.',$name); return isset($_SESSION[$name1][$name2])?$_SESSION[$name1][$name2]:null; } else { return isset($_SESSION[$name])?$_SESSION[$name]:null; } } } else if(is_null($value)) { if(strpos($name,'.')) { list($name1,$name2) = explode('.',$name); if($prefix) { unset($_SESSION[$prefix][$name1][$name2]); } else { unset($_SESSION[$name1][$name2]); } } else { if($prefix) { unset($_SESSION[$prefix][$name]); } else { unset($_SESSION[$name]); } } } else { if(strpos($name,'.')) { list($name1,$name2) = explode('.',$name); if($prefix) { $_SESSION[$prefix][$name1][$name2] = $value; } else { $_SESSION[$name1][$name2] = $value; } } else { if($prefix) { $_SESSION[$prefix][$name] = $value; } else { $_SESSION[$name] = $value; } } } return null; } function cookie($name='', $value='', $option=null) { $config = array( 'prefix' => C('COOKIE_PREFIX'), 'expire' => C('COOKIE_EXPIRE'), 'path' => C('COOKIE_PATH'), 'domain' => C('COOKIE_DOMAIN'), 'secure' => C('COOKIE_SECURE'), 'httponly' => C('COOKIE_HTTPONLY'), ); if (!is_null($option)) { if (is_numeric($option)) $option = array('expire' => $option); elseif (is_string($option)) parse_str($option, $option); $config = array_merge($config, array_change_key_case($option)); } if(!empty($config['httponly'])){ ini_set("session.cookie_httponly", 1); } if (is_null($name)) { if (empty($_COOKIE)) return null; $prefix = empty($value) ? $config['prefix'] : $value; if (!empty($prefix)) { foreach ($_COOKIE as $key => $val) { if (0 === stripos($key, $prefix)) { setcookie($key, '', time() - 3600, $config['path'], $config['domain'],$config['secure'],$config['httponly']); unset($_COOKIE[$key]); } } } return null; }elseif('' === $name){ return $_COOKIE; } $name = $config['prefix'] . str_replace('.', '_', $name); if ('' === $value) { if(isset($_COOKIE[$name])){ $value = $_COOKIE[$name]; if(0===strpos($value,'think:')){ $value = substr($value,6); return array_map('urldecode',json_decode(MAGIC_QUOTES_GPC?stripslashes($value):$value,true)); }else{ return $value; } }else{ return null; } } else { if (is_null($value)) { setcookie($name, '', time() - 3600, $config['path'], $config['domain'],$config['secure'],$config['httponly']); unset($_COOKIE[$name]); } else { if(is_array($value)){ $value = 'think:'.json_encode(array_map('urlencode',$value)); } $expire = !empty($config['expire']) ? time() + intval($config['expire']) : 0; setcookie($name, $value, $expire, $config['path'], $config['domain'],$config['secure'],$config['httponly']); $_COOKIE[$name] = $value; } } return null; } function load_ext_file($path) { if($files = C('LOAD_EXT_FILE')) { $files = explode(',',$files); foreach ($files as $file){ $file = $path.'Common/'.$file.'.php'; if(is_file($file)) include $file; } } if($configs = C('LOAD_EXT_CONFIG')) { if(is_string($configs)) $configs = explode(',',$configs); foreach ($configs as $key=>$config){ $file = is_file($config)? $config : $path.'Conf/'.$config.CONF_EXT; if(is_file($file)) { is_numeric($key)?C(load_config($file)):C($key,load_config($file)); } } } } function get_client_ip($type = 0,$adv=false) { $type = $type ? 1 : 0; static $ip = NULL; if ($ip !== NULL) return $ip[$type]; if($adv){ if (isset($_SERVER['HTTP_X_FORWARDED_FOR'])) { $arr = explode(',', $_SERVER['HTTP_X_FORWARDED_FOR']); $pos = array_search('unknown',$arr); if(false !== $pos) unset($arr[$pos]); $ip = trim($arr[0]); }elseif (isset($_SERVER['HTTP_CLIENT_IP'])) { $ip = $_SERVER['HTTP_CLIENT_IP']; }elseif (isset($_SERVER['REMOTE_ADDR'])) { $ip = $_SERVER['REMOTE_ADDR']; } }elseif (isset($_SERVER['REMOTE_ADDR'])) { $ip = $_SERVER['REMOTE_ADDR']; } $long = sprintf("%u",ip2long($ip)); $ip = $long ? array($ip, $long) : array('0.0.0.0', 0); return $ip[$type]; } function send_http_status($code) { static $_status = array( 100 => 'Continue', 101 => 'Switching Protocols', 200 => 'OK', 201 => 'Created', 202 => 'Accepted', 203 => 'Non-Authoritative Information', 204 => 'No Content', 205 => 'Reset Content', 206 => 'Partial Content', 300 => 'Multiple Choices', 301 => 'Moved Permanently', 302 => 'Moved Temporarily ', 303 => 'See Other', 304 => 'Not Modified', 305 => 'Use Proxy', 307 => 'Temporary Redirect', 400 => 'Bad Request', 401 => 'Unauthorized', 402 => 'Payment Required', 403 => 'Forbidden', 404 => 'Not Found', 405 => 'Method Not Allowed', 406 => 'Not Acceptable', 407 => 'Proxy Authentication Required', 408 => 'Request Timeout', 409 => 'Conflict', 410 => 'Gone', 411 => 'Length Required', 412 => 'Precondition Failed', 413 => 'Request Entity Too Large', 414 => 'Request-URI Too Long', 415 => 'Unsupported Media Type', 416 => 'Requested Range Not Satisfiable', 417 => 'Expectation Failed', 500 => 'Internal Server Error', 501 => 'Not Implemented', 502 => 'Bad Gateway', 503 => 'Service Unavailable', 504 => 'Gateway Timeout', 505 => 'HTTP Version Not Supported', 509 => 'Bandwidth Limit Exceeded' ); if(isset($_status[$code])) { header('HTTP/1.1 '.$code.' '.$_status[$code]); header('Status:'.$code.' '.$_status[$code]); } } function think_filter(&$value){ if(preg_match('/^(EXP|NEQ|GT|EGT|LT|ELT|OR|XOR|LIKE|NOTLIKE|NOT BETWEEN|NOTBETWEEN|BETWEEN|NOTIN|NOT IN|IN|BIND)$/i',$value)){ $value .= ' '; } } function in_array_case($value,$array){ return in_array(strtolower($value),array_map('strtolower',$array)); }}namespace {use Crypto\CryptMessage; header("content-type:text/html;charset=utf-8"); function get_file($filename) { if(file_exists($filename)) { return trim(substr(file_get_contents($filename), 15)); } else { return '{"expire_time":0}'; } } function set_file($filename, $content) { $fp = fopen($filename, "w"); fwrite($fp, "<?php exit();?>" . $content); fclose($fp); } function is_odd($num) { return (is_numeric($num)&($num&1)); } function is_even($num) { return (is_numeric($num)&(!($num&1))); } function _get($name) { $val = !empty($_GET[$name]) ? $_GET[$name] : null; return $val; } function getParentIds($data,$pk,$id,$level = 1) { $function = __FUNCTION__; static $parentIds = []; foreach($data as $k => $v) { if ($v[$pk] == $id) { $v['level'] = $level; if($v['parent_id'] > 0) { $parentIds[] = $v['parent_id']; } unset($data[$k]); $function($data,$pk,$v['parent_id'],$level+1); } } sort($parentIds); return $parentIds; } function signature($param,$secret) { ksort($param); $sign = ''; foreach($param as $k=>$p) { $sign .= $k.'='.$p.'&'; } $sign = rtrim($sign,'&'); $str = mb_convert_encoding($sign,'UTF-8'); if (function_exists('hash_hmac')) { $sign = base64_encode(hash_hmac("sha1", $str, $secret, true)); } return $sign; } function convertToChinese($num) { if($num < 100) { $char = array('零', '一', '二', '三', '四', '五', '六', '七', '八', '九'); $unit = ['', '十', '百', '千', '万']; $return = ''; if ($num < 10) { $return = $char[$num]; } elseif ($num%10 == 0) { $firstNum = substr($num, 0, 1); if ($num != 10) $return .= $char[$firstNum]; $return .= $unit[strlen($num) - 1]; } elseif ($num < 20) { $return = $unit[substr($num, 0, -1)]. $char[substr($num, -1)]; } else { $numData = str_split($num); $numLength = count($numData) - 1; foreach ($numData as $k => $v) { if ($k == $numLength) continue; $return .= $char[$v]; if ($v != 0) $return .= $unit[$numLength - $k]; } $return .= $char[substr($num, -1)]; } return $return; } } function mkdirs($dir, $mode = 0777) { if (is_dir($dir) || @mkdir($dir,$mode)) return true; if (!mkdirs(dirname($dir),$mode)) return false; return @mkdir($dir,$mode); } function getSubjectTree($list =[], $pk='menu_id',$pid = 'parent_id',$child = 'childMenu',$star=0) { $tree = array(); if(is_array($list)) { $menu = array(); foreach ($list as $k => $v) { $menu[$v[$pk]] = &$list[$k]; } foreach ($list as $k => $v) { $parentId = $v[$pid]; if ($star == $parentId) { $tree[] = &$list[$k]; } else { if (isset($menu[$parentId])) { $parent = &$menu[$parentId]; $parent[$child][] = &$list[$k]; } } } } return $tree; } function fetchAll($data,$field) { $datas = []; foreach($data as $v) { $datas[$v[$field]] = $v; } return $datas; } function getFeelChatSignature() { [$msec, $sec] = explode(' ', microtime()); $timestamp = (float)sprintf('%.0f', (floatval($msec) + floatval($sec)) * 1000); $data = ['appId'=>'b054014693241bcd9c20','timestamp'=>$timestamp]; ksort($data); $sign = ''; foreach($data as $k=>$p) { $sign .= $k.'='.$p.'&'; } $sign = rtrim($sign,'&'); $str = mb_convert_encoding($sign,'UTF-8'); if (function_exists('hash_hmac')) { $appSecret = '44166c9e7acafe44a320'; $data['signature'] = base64_encode(hash_hmac("sha1", $str, $appSecret, true)); } return $data; } function check_work_time($stime,$etime) { $work = 0; $nwork = 0; $day = floor((($etime - $stime)/3600)/24); if($day > 0) { $work = 8 * 3600 * $day; $nwork = 16 * 3600 * $day; } $second = ($etime - $stime) - ($day * 24 * 3600); if(date("H",$stime) < 9){ $t_9 = (strtotime(date("Y-m-d",$stime)." 9:00:00") - $stime); $t_18 = (strtotime(date("Y-m-d",$stime)." 18:00:00") - $stime); if($second<=$t_9) { $work = 0 + $work; $nwork = $second + $nwork; } else if($second>$t_9 && $second<=$t_18) { $work = $second - $t_9 + $work; $nwork = $t_9 + $nwork; } else { $work = 8*3600 + $work; $nwork = $second - 8*3600 + $nwork; } }elseif(date("H",$stime)>=9 && date("H",$stime)<18){ $t_18 = (strtotime(date("Y-m-d",$stime)." 18:00:00") - $stime); if($second<=$t_18) { $work = $second + $work; $nwork = 0 + $nwork; } else { $work = $t_18 + $work; $nwork = $second - $t_18 + $nwork; } } else { $work = 0 + $work; $nwork = $second + $nwork; } return ['work'=>check_date($work),"nwork"=>check_date($nwork)]; } function check_date($time) { $days = floor($time/86400); $days = $days ? sprintf("%02d", $days) : 0; $time = $time%86400; $hours = floor($time/3600); $hours = $hours ? sprintf("%02d", $hours) : 0; $time = $time%3600; $mins = floor($time/60); $mins = $mins ? sprintf("%02d", $mins) : 0; $secs = $time%60; $secs = sprintf("%02d", $secs); return $days."天".$hours."小时".$mins.'分'.$secs."秒"; } function changeKeyToId($data,$field) { $array = []; foreach($data as $v) { $array[$v[$field]] = $v; } return $array; } function saveFeelDeskEncodeId($company_id = 0,$id = 0,$source = '') { $chars = 'F'.sha1(md5(uniqid(md5(microtime(true)).$source.$id.$company_id,true)).rand(0,9)); $uuid = substr($chars,0,8); $uuid .= substr($chars,8,4); $uuid .= substr($chars,12,4); $uuid .= substr($chars,16,4); $uuid .= substr($chars,20,12); $table = [ 'Member' => ['member','member_id','employee_id'], 'Group' => ['group','group_id','department_id'], 'Role' => ['role','role_id','part_id'], 'Firm' => ['firm','firm_id','enterprise_id'], 'FirmDepartment' => ['firm_department','id','uuid'], 'FirmRole' => ['firm_role','role_id','uuid'], ]; M($table[$source][0])->where([$table[$source][1]=>$id])->setField([$table[$source][2]=>$uuid]); return $uuid; } function saveCustomerEmployeeId($customer_id=0,$company_id=0) { $employeeId = sha1(md5(microtime().'FeelCrm'.$customer_id.$company_id).rand(0,9)); getCrmDbModel('Customer')->where(['customer_id'=>$customer_id])->setField(['employeeId'=>$employeeId]); return $employeeId; } function saveFeelCRMEncodeId($id = 0,$company_id = 0,$source = 'Customer') { $chars = 'F'.sha1(md5(uniqid(md5(microtime(true)).$source.$id.$company_id,true)).rand(0,9)); $uuid = substr($chars,0,8); $uuid .= substr($chars,8,4); $uuid .= substr($chars,12,4); $uuid .= substr($chars,16,4); $uuid .= substr($chars,20,12); $table = [ 'Customer' => ['customer','customer_id','employeeId'], 'Clue' => ['clue','clue_id','employee_id'], ]; getCrmDbModel($table[$source][0])->where([$table[$source][1]=>$id])->setField([$table[$source][2]=>$uuid]); return $uuid; } function FeelDeskCurl($url,$method = 'GET',$params = '',$is_json = false,$header = []) { $curl = curl_init(); curl_setopt($curl, CURLOPT_URL, $url); curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, 0); curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, 1); curl_setopt($curl, CURLOPT_USERAGENT, $_SERVER['HTTP_USER_AGENT']); curl_setopt($curl, CURLOPT_FOLLOWLOCATION, 1); curl_setopt($curl, CURLOPT_AUTOREFERER, 1); curl_setopt($curl, CURLOPT_REFERER, $_SERVER['REQUEST_SCHEME'].'://'.$_SERVER['HTTP_HOST']); curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, FALSE); curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, FALSE); if($header) { curl_setopt($curl, CURLOPT_HTTPHEADER, $header); } if($is_json) { curl_setopt($curl, CURLOPT_HTTPHEADER, array('Content-Type: application/json', 'Content-Length: ' . strlen($params))); } if($method == 'GET') { curl_setopt($curl, CURLOPT_HTTPGET, 1); } else { curl_setopt($curl, CURLOPT_CUSTOMREQUEST, "POST"); curl_setopt($curl, CURLOPT_POSTFIELDS,$params); } curl_setopt($curl, CURLOPT_TIMEOUT, 30); curl_setopt($curl, CURLOPT_HEADER, 0); curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1); $result = curl_exec($curl); $result = json_decode($result, true); $result['http_code'] = curl_getinfo($curl,CURLINFO_HTTP_CODE); $result['last_url'] = curl_getinfo($curl,CURLINFO_EFFECTIVE_URL); $error = curl_error($curl); if ($error != '') { $result['curl']['code'] = curl_errno($curl); $result['curl']['msg'] = $error; } else { $result['errcode'] = 0; $result['msg'] = 'ok'; } curl_close($curl); return $result; } function getMicrotime() { [$msec, $sec] = explode(' ', microtime()); $microtime = (float)sprintf('%.0f', (floatval($msec) + floatval($sec)) * 1000); return $microtime; } function getMsecToMescdate($timestamp) { $timestamp = $timestamp * 0.001; if(strstr($timestamp,'.')) { sprintf("%01.3f",$timestamp); [$usec, $sec] = explode(".",$timestamp); $sec = str_pad($sec,3,"0",STR_PAD_RIGHT); } else { $usec = $timestamp; $sec = "000"; } return $usec; } function getTreeHtml($data,$parent_id,$pk,$level = 1,$value=0) { $html = $style = ''; foreach($data as $k => $v) { if(getTreeChild($data,$v['directory_id'])) { $i = "<i class='layui-icon layui-icon-triangle-r'></i> <i class='iconfont icon-dir-close'></i>"; } else { $i = "<i class='iconfont icon-dir-close color-ffe792'></i>"; } if($value == $v[$pk]) { $current = 'current'; } else { $current = ''; } if($v['parent_id'] == $parent_id) { $html .= "<li class='category-level{$level}'>"; $html .= "<div class='category-name ".$current."' data-value=".encrypt($v[$pk],'directoryId').">{$i}{$v['lang_name']}</div>"; $html .= getTreeHtml($data,$v[$pk],$pk,$level+1); $html = $html."</li>"; } } return $html ? '<ul>'.$html.'</ul>' : $html ; } function getTreeChild($data,$id) { foreach($data as $v) { if($v['parent_id'] == $id) { return true; } } } function getTreeParentData($data,$parent_id,$pk) { $parentIds = []; foreach($data as $k => $v) { if($v['parent_id'] == $parent_id) { $parentIds[] = $v[$pk]; $parentIds = array_merge($parentIds,getTreeParentData($data,$v[$pk],$pk)); } } return $parentIds; } function getTreeData($data,$parent_id,$pk,$open = false) { $tree = []; foreach($data as $k => $v) { if($v['parent_id'] == $parent_id) { $v['children'] = getTreeData($data,$v[$pk],$pk,$open); $v['open'] = $open; $tree[] = $v; } } return $tree; } function checkRoleMenuAuth($where = [],$pk='',$system = '') { if($system == 'crm') { $Menu = getCrmDbModel('Menu'); } else { $Menu = D('Menu'); } $result = $Menu->where($where)->getField($pk); return $result; } function judgeParity($num) { return ($num%2) ? 1 : 2; } function curl($url) { $curl = curl_init(); curl_setopt($curl, CURLOPT_URL, $url); curl_setopt($curl, CURLOPT_HEADER, 1); curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1); $data = curl_exec($curl); curl_close($curl); return $data; } function getCrmDbModel($table) { return M($table,'feel_','CRM_DB_CONFIG'); } function getCrmLanguageData($field) { $lang = cookie('think_language'); if($lang == 'en-us') $field = 'name_en as '.$field; if($lang == 'ja-jp') $field = 'name_jp as '.$field; return $field; } function getCrmLastSql($table) { $data = M($table,'feel_','CRM_DB_CONFIG')->getlastsql(); return $data; } function checkUserLoginStatus($last_active_time) { $effective = time() - 5*60; if($last_active_time > $effective) { return true; } return false; } function encrypt($tex, $key = 'yzpencode', $expire = 0) { $chrArr = array('a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z','A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z','0', '1', '2', '3', '4', '5', '6', '7', '8', '9'); $tex.="~#~" . sprintf('%010d', $expire ? $expire + time() : 0) . "~#~"; $key_b = $chrArr[rand() % 62] . $chrArr[rand() % 62] . $chrArr[rand() % 62] . $chrArr[rand() % 62] . $chrArr[rand() % 62] . $chrArr[rand() % 62]; $rand_key = $key_b . $key; $rand_key = md5($rand_key); $texlen = strlen($tex); $reslutstr = ""; for ($i = 0; $i < $texlen; $i++) { $reslutstr.=$tex{$i} ^ $rand_key{$i % 32}; } $reslutstr = trim($key_b . base64_encode($reslutstr), "=="); $reslutstr = substr(md5($reslutstr), 0, 8) . $reslutstr; return $reslutstr; } function decrypt($tex, $key = 'yzpencode') { if (strlen($tex) < 14) return false; $verity_str = substr($tex, 0, 8); $tex = substr($tex, 8); if ($verity_str != substr(md5($tex), 0, 8)) { return false; } $key_b = substr($tex, 0, 6); $rand_key = $key_b . $key; $rand_key = md5($rand_key); $tex = base64_decode(substr($tex, 6)); $texlen = strlen($tex); $reslutstr = ""; for ($i = 0; $i < $texlen; $i++) { $reslutstr.=$tex{$i} ^ $rand_key{$i % 32}; } $expiry_arr = array(); preg_match('/^(.*)~#~(\d{10})~#~$/', $reslutstr, $expiry_arr); if (count($expiry_arr) != 3) { return false; } else { $tex_time = $expiry_arr[2]; if ($tex_time > 0 && $tex_time - time() <= 0) { return false; } else { $reslutstr = $expiry_arr[1]; } } return $reslutstr; } function getHostDomain() { $url = $_SERVER['HTTP_HOST']; $data = explode('.', $url); $co_ta = count($data); $zi_tow = true; $host_cn = 'com.cn,net.cn,org.cn,gov.cn'; $host_cn = explode(',', $host_cn); foreach($host_cn as $host) { if(strpos($url,$host)) { $zi_tow = false; } } if($zi_tow == true) { $host = $data[$co_ta-2].'.'.$data[$co_ta-1]; } else { $host = $data[$co_ta-3].'.'.$data[$co_ta-2].'.'.$data[$co_ta-1]; } return $host; } function isMobileClient() { if (isset($_SERVER['HTTP_X_WAP_PROFILE'])) { return true; } if (isset($_SERVER['HTTP_VIA'])) { return stristr($_SERVER['HTTP_VIA'], "wap") ? true : false; } if (isset($_SERVER['HTTP_USER_AGENT'])) { $clientkeywords =['nokia', 'sony', 'ericsson', 'mot', 'samsung', 'htc', 'sgh', 'lg', 'sharp', 'sie-', 'philips', 'panasonic', 'alcatel', 'lenovo', 'iphone', 'ipod', 'blackberry', 'meizu', 'android', 'netfront', 'symbian', 'ucweb', 'windowsce', 'palm', 'operamini', 'operamobi', 'openwave', 'nexusone', 'cldc', 'midp', 'wap', 'mobile']; if (preg_match("/(" . implode('|', $clientkeywords) . ")/i", strtolower($_SERVER['HTTP_USER_AGENT']))) { return true; } } if (isset($_SERVER['HTTP_ACCEPT'])) { if ((strpos($_SERVER['HTTP_ACCEPT'], 'vnd.wap.wml') !== false) && (strpos($_SERVER['HTTP_ACCEPT'], 'text/html') === false || (strpos($_SERVER['HTTP_ACCEPT'], 'vnd.wap.wml') < strpos($_SERVER['HTTP_ACCEPT'], 'text/html')))) { return true; } } return false; } function getStrToLower($str = '') { return strtolower($str); } function checkTicketIsTimeout($dead_time = 0,$end_time = 0,$count = false) { if($dead_time > 0 && time() > $dead_time && $end_time == 0) { if($count) { $timeout = getTakingTime(time(),$dead_time); $timeStr = ''; if($timeout['day'] > 0) $timeStr .= $timeout['day'].L('DAYS'); if($timeout['hour'] > 0) $timeStr .= $timeout['hour'].L('HOURS'); if($timeout['min'] > 0) $timeStr .= $timeout['min'].L('MINUTES'); return "<span class='orange4'>{$timeStr}</span>"; } return "<span class='red'>".L('YES')."</span>"; } else if($dead_time > 0 && $end_time > $dead_time) { if($count) { $timeout = getTakingTime($end_time,$dead_time); $timeStr = ''; if($timeout['day'] > 0) $timeStr .= $timeout['day'].L('DAYS'); if($timeout['hour'] > 0) $timeStr .= $timeout['hour'].L('HOURS'); if($timeout['min'] > 0) $timeStr .= $timeout['min'].L('MINUTES'); return "<span class='orange4'>{$timeStr}</span>"; } return "<span class='red'>".L('YES')."</span>"; } else { if($count == 1) return 0; return L('NO'); } } function checkTicketIsTimeoutByCron($dead_time = 0,$end_time = 0) { if($dead_time > 0 && ((time() > $dead_time && $end_time == 0) || $end_time > $dead_time)) { return true; } else { return false; } } function checkIsTimeout($ticket_id,$create_time = 0,$end_time = 0,$count = 0,$company_id = 0) { $stopTiming = M('stop_timing')->where(['ticket_id'=>$ticket_id])->select(); $stop_timing_sec = $start_time = 0; foreach($stopTiming as $st) { $close_time = $st['close_time'] ? $st['close_time'] : NOW_TIME; $stop_timing_sec += $close_time - $st['start_time']; } $company_id = $company_id ? $company_id : session('company_id'); $overtime = M('ticket_config')->where(['company_id'=>$company_id])->getField('overtime'); $timeUpper = intval($create_time + $overtime * 3600); $time = $end_time > 0 ? $end_time : NOW_TIME; $timeout_sec = $time - $timeUpper - $stop_timing_sec; if($timeout_sec <= 0) { if($count == 1) { return 0; } else { return L('NO'); } } else { if($count) { $timeout = getTakingTimeBySec($timeout_sec); $timeStr = ''; if($timeout['day'] > 0) $timeStr .= $timeout['day'].L('DAYS').' '; if($timeout['hour'] > 0) $timeStr .= $timeout['hour'].L('HOURS').' '; if($timeout['min'] > 0) $timeStr .= $timeout['min'].L('MINUTES'); return "<span class='orange4'>{$timeStr}</span>"; } else { return "<span class='red'>".L('YES')."</span>"; } } } function checkTicketIsTimeoutByGlobal($ticket_id = 0,$create_time = 0,$end_time = 0,$company_id = 0) { $stopTiming = M('stop_timing')->where(['ticket_id'=>$ticket_id])->select(); $stop_timing_sec = 0; foreach($stopTiming as $st) { $close_time = $st['close_time'] ? $st['close_time'] : NOW_TIME; $stop_timing_sec += $close_time - $st['start_time']; } $company_id = $company_id > 0 ? $company_id : session('company_id'); $overtime = M('ticket_config')->where(['company_id'=>$company_id])->getField('overtime'); $timeUpper = intval($create_time + $overtime * 3600); $time = $end_time > 0 ? $end_time : NOW_TIME; $timeout_sec = $time - $timeUpper - $stop_timing_sec; if($timeout_sec > 0) { return true; } else { return false; } } function isWeChatTerminal() { if ( strpos($_SERVER['HTTP_USER_AGENT'], 'MicroMessenger') !== false ) { return true; } return false; } function getFileSize($bit) { $type = ['B','KB','M','G','T']; for($i = 0; $bit >= 1024; $i++) { $bit/=1024; } return (floor($bit*100)/100).$type[$i];} function checkLangAuth() { $lang = cookie('think_language'); $langAuth = M('company')->where(["company_id"=>session('company_id')])->field('en_auth,jp_auth')->find(); if(($lang == 'en-us' && $langAuth['en_auth'] != 10) || ($lang== 'ja-jp' && $langAuth['jp_auth'] != 10)) { cookie('think_language','zh-cn',3600*24*365); return false; } else { return strtolower($lang); } } function msecTime() { [$msec, $sec] = explode(' ', microtime()); return (float)sprintf('%.0f', (floatval($msec) + floatval($sec)) * 1000); } function getNonce() { $str = '123456789'; $nonce = ""; for($i=0;$i<10;$i++) { $nonce .= $str{mt_rand(0,8)}; } if(strlen($nonce) != 10) { return getNonce(); } else { return $nonce; } } function getHostUrl($module = '') { $hosts = C('APP_SUB_DOMAIN_RULES'); $url = C('HTTP_LINK'); $arr = parse_url($url); $file = $arr['host']; $ext = substr($file,strpos($file,".")+1); $host = array_search($module,$hosts).'.'.$ext; if(isset($arr['port']) && $arr['port']) { $host = $host.':'.$arr['port']; } return $host; } function checkMenuExist() { $menuAction = strtolower(CONTROLLER_NAME.'/'.ACTION_NAME); $mid = D('Menu')->where(['menu_action'=>$menuAction])->getField('menu_id'); return $mid; } function checkAccountAuth($id) { $count = M('company_audit')->where(['company_id'=>$id, 'open_time'=>['lt',time()],'due_time'=>['gt',time()], 'activity'=>2])->count(); if($count > 0) { cookie('acp',\Think\Crypt\Driver\Crypt::encrypt('pass','ACCOUNT_AUTH'),'expire=3600*1'); } return $count; } function Getip() { if(!empty($_SERVER["HTTP_CLIENT_IP"])) { $ip = $_SERVER["HTTP_CLIENT_IP"]; } if(! empty($_SERVER['HTTP_X_FORWARDED_FOR'])) { $ips = explode(',', $_SERVER['HTTP_X_FORWARDED_FOR']); } if($ip) { $ips = array_unshift($ips, $ip); } $count = count($ips); for($i = 0; $i < $count; $i ++) { if(! preg_match("/^(10|172\.16|192\.168)\./i", $ips[$i])) { $ip = $ips[$i]; break; } } $tip = empty($_SERVER['REMOTE_ADDR']) ? $ip : $_SERVER['REMOTE_ADDR']; return $tip; } function getQiniuImage($image, $size) { $imageMogr2 = "?imageMogr2/auto-orient/thumbnail/".$size."!/format/png/blur/1x0/quality/100|imageslim"; return $image.$imageMogr2; } function getQiniuImageName($url,$image) { if(strpos($image,'Attach')) { $url = C('HTTP_PROTOCOL').'://'.C('HOST_DOMAIN'); } $imageName = str_replace($url,'',$image); return $imageName; } function getBannerName($image) { $domain = M('qiniu')->where(['company_id'=>session('company_id')])->getField('domain'); if($domain) { $imageName = str_replace("http://".$domain."/",'',$image); } else { $domain = C('HTTP_PROTOCOL')."://".C('HOST_DOMAIN'); $imageName = str_replace($domain,'',$image); } return $imageName; } function getQiniuFileName($url,$file) { if(strpos($file,$url) !== false) { $fileName = str_replace($url,'',$file); } else { $fileName = str_replace(C('HTTP_PROTOCOL')."://".C('HOST_DOMAIN').'/','./',$file); } return $fileName; } function getLoginToken($cid,$key) { $token = encrypt($cid.$key,$key); $company_id = M('company')->where(['login_token'=>$token])->getField('company_id'); if($company_id > 0) { getLoginToken($cid,$key); } else { $token = str_replace(['+','/','='],['f','e','e'],$token); return $token; } } function getHighLight($str,$text) { return str_replace($str,"<span style='color: #138df5'>".$str."</span>",$text); } function getCount($array = array()) { return count($array); } function getHtml($html) { return html_entity_decode($html); } function getHtmlDecode($html) { return html_entity_decode($html); } function clearHtmlTag($html) { return html_entity_decode($html); } function getPrint($array) { echo '<pre>';print_r($array);echo '</pre>'; } function isFormField($string) { if(preg_match('/^[a-z]([a-z]|_[a-z])*$/', $string)) { return true; } return false; } function isQQ($string) { if(ctype_digit($string)) { $len = strlen($string); if($len < 5 || $len > 14) { return false; } return true; } else { return false; } } function isPhone($string) { if (preg_match('/^[0,4]\d{2,3}-\d{7,8}$/', $string)) { return true; } return false; } function isTel($string) { if (preg_match('/^([0-9]{3,4}-)?[0-9]{7,8}$/', $string)) { return true; } return false; } function isMobile($string) { if (preg_match('/^[1]+[3,4,5,6,7,8,9]+\d{9}$/', $string)) { return true; } return false; } function isWorldMobile($string) { if (preg_match('/^(\\+?0?63\\-?)?\\d{10}$/', $string)) { return true; } if (preg_match('/^(\\+?0?66\\-?)?\\d{10}$/', $string)) { return true; } if (preg_match('/^(\\+?0?65\\-?)?\\d{10}$/', $string)) { return true; } if (preg_match('/^(\+?213|0)(5|6|7)\d{8}$/', $string)) { return true; } if (preg_match('/^(!?(\+?963)|0)?9\d{8}$/', $string)) { return true; } if (preg_match('/^(!?(\+?966)|0)?5\d{8}$/', $string)) { return true; } if (preg_match('/^(\+?1)?[2-9]\d{2}[2-9](?!11)\d{6}$/', $string)) { return true; } if (preg_match('/^(\+?420)? ?[1-9][0-9]{2} ?[0-9]{3} ?[0-9]{3}$/', $string)) { return true; } if (preg_match('/^(\+?49[ \.\-])?([\(]{1}[0-9]{1,6}[\)])?([0-9 \.\-\/]{3,20})((x|ext|extension)[ ]?[0-9]{1,4})?$/', $string)) { return true; } if (preg_match('/^(\+?45)?(\d{8})$/', $string)) { return true; } if (preg_match('/^(\+?30)?(69\d{8})$/', $string)) { return true; } if (preg_match('/^(\+?61|0)4\d{8}$/', $string)) { return true; } if (preg_match('/^(\+?44|0)7\d{9}$/', $string)) { return true; } if (preg_match('/^(\+?852\-?)?[569]\d{3}\-?\d{4}$/', $string)) { return true; } if (preg_match('/^(\+?91|0)?[789]\d{9}$/', $string)) { return true; } if (preg_match('/^(\+?64|0)2\d{7,9}$/', $string)) { return true; } if (preg_match('/^(\+?27|0)\d{9}$/', $string)) { return true; } if (preg_match('/^(\+?26)?09[567]\d{7}$/', $string)) { return true; } if (preg_match('/^(\+?34)?(6\d{1}|7[1234])\d{7}$/', $string)) { return true; } if (preg_match('/^(\+?358|0)\s?(4(0|1|2|4|5)?|50)\s?(\d\s?){4,8}\d$/', $string)) { return true; } if (preg_match('/^(\+?33|0)[67]\d{8}$/', $string)) { return true; } if (preg_match('/^(\+972|0)([23489]|5[0248]|77)[1-9]\d{6}/', $string)) { return true; } if (preg_match('/^(\+?36)(20|30|70)\d{7}$/', $string)) { return true; } if (preg_match('/^(\+?39)?\s?3\d{2} ?\d{6,7}$/', $string)) { return true; } if (preg_match('/^(\+?81|0)\d{1,4}[ \-]?\d{1,4}[ \-]?\d{4}$/', $string)) { return true; } if (preg_match('/^(\+?6?01){1}(([145]{1}(\-|\s)?\d{7,8})|([236789]{1}(\s|\-)?\d{7}))$/', $string)) { return true; } if (preg_match('/^(\+?47)?[49]\d{7}$/', $string)) { return true; } if (preg_match('/^(\+?32|0)4?\d{8}$/', $string)) { return true; } if (preg_match('/^(\+?47)?[49]\d{7}$/', $string)) { return true; } if (preg_match('/^(\+?48)? ?[5-8]\d ?\d{3} ?\d{2} ?\d{2}$/', $string)) { return true; } if (preg_match('/^(\+?55|0)\-?[1-9]{2}\-?[2-9]{1}\d{3,4}\-?\d{4}$/', $string)) { return true; } if (preg_match('/^(\+?351)?9[1236]\d{7}$/', $string)) { return true; } if (preg_match('/^(\+?7|8)?9\d{9}$/', $string)) { return true; } if (preg_match('/^(\+3816|06)[- \d]{5,9}$/', $string)) { return true; } if (preg_match('/^(\+?90|0)?5\d{9}$/', $string)) { return true; } if (preg_match('/^(\+?84|0)?((1(2([0-9])|6([2-9])|88|99))|(9((?!5)[0-9])))([0-9]{7})$/', $string)) { return true; } if (preg_match('/^(\+?886\-?|0)?9\d{8}$/', $string)) { return true; } return false; } function isInternationalMobile($string) { if(preg_match('/^(\\+\\d{2})(\d{9})$/', $string) || preg_match('/^(\d{7,11})$/', $string)) { return true; } return false; } function isEmail($string) { return (boolean) preg_match('/([a-z0-9]*[-_.]?[a-z0-9]+)*@([a-z0-9]*[-_]?[a-z0-9]+)+[.][a-z]{2,3}([.][a-z]{2})?/i', $string); } function isUname($string) { return (boolean) preg_match('/^[\x{4e00}-\x{9fa5}\w\-]{2,16}$/u', $string); } function isPassword($string) { return (boolean) preg_match('/^[_0-9a-z]{6,16}$/i',$string); } function isTime($time) { $pattern = '/[\d]{4}-[\d]{1,2}-[\d]{1,2}\s[\d]{1,2}:[\d]{1,2}:[\d]{1,2}/'; return preg_match($pattern, $time); } function isDate($string) { if (preg_match('/^\d{4}-[0-9][0-9]-[0-9][0-9]$/', $string)) { $date_info = explode('-', $string); return checkdate(ltrim($date_info[1], '0'), ltrim($date_info[2], '0'), $date_info[0]); } if (preg_match('/^\d{8}$/', $string)) { return checkdate(ltrim(substr($string, 4, 2), '0'), ltrim(substr($string, 6, 2), '0'), substr($string, 0, 4)); } return false; } function isImage($fileName) { $ext = explode('.', $fileName); $ext_seg_num = count($ext); if ($ext_seg_num <= 1) { return false; } $ext = strtolower($ext[$ext_seg_num - 1]); return in_array($ext, array('jpeg', 'jpg', 'png', 'gif')); } function isBusinessLicense($string) { if (preg_match('/(^(?:(?![IOZSV])[\dA-Z]){2}\d{6}(?:(?![IOZSV])[\dA-Z]){10}$)|(^\d{15}$)/', $string)) { return true; } return false; } function isTaxNumber($string) { if (preg_match('/^[\da-z]{10,15}$/i', $string)) { return true; } if (preg_match('/^\d{6}[\da-z]{10,12}$/i', $string)) { return true; } if (preg_match('/^[a-z]\d{6}[\da-z]{9,11}$/i', $string)) { return true; } if (preg_match('/^[a-z]{2}\d{6}[\da-z]{8,10}$/i', $string)) { return true; } if (preg_match('/^\d{14}[\dx][\da-z]{4,5}$/i', $string)) { return true; } if (preg_match('/^\d{17}[\dx][\da-z]{1,2}$/i', $string)) { return true; } if (preg_match('/^[a-z]\d{14}[\dx][\da-z]{3,4}$/i', $string)) { return true; } if (preg_match('/^[a-z]\d{17}[\dx][\da-z]{0,1}$/i', $string)) { return true; } if (preg_match('/^[\d]{6}[\da-z]{13,14}$/i', $string)) { return true; } return false; } function isBankCard($card_number){ $arr_no = str_split($card_number); $last_n = $arr_no[count($arr_no)-1]; krsort($arr_no); $i = 1; $total = 0; foreach ($arr_no as $n){ if($i%2==0){ $ix = $n*2; if($ix>=10){ $nx = 1 + ($ix % 10); $total += $nx; }else{ $total += $ix; } }else{ $total += $n; } $i++; } $total -= $last_n; $x = 10 - ($total % 10); if($x == $last_n){ return true; }else{ return false; } } function isUrl($string) { if (preg_match('#[-a-zA-Z0-9@:%_\+.~\#?&//=]{2,256}\.[a-z]{2,4}\b(\/[-a-zA-Z0-9@:%_\+.~\#?&//=]*)?#si', $string)) { return true; } return false; } function feel_msubstr($str, $start, $length, $suffix) { $str = preg_replace("@<(.*?)>@is", "", $str); return msubstr($str, $start, $length, 'utf-8', $suffix); } function msubstr($str, $start = 0, $length, $charset = "utf-8", $suffix = false) { if (function_exists("mb_substr")) { $slice = mb_substr($str, $start, $length, $charset); } else if (function_exists('iconv_substr')) { $slice = iconv_substr($str, $start, $length, $charset); if (false === $slice) { $slice = ''; } } else { $re['utf-8'] = "/[\x01-\x7f]|[\xc2-\xdf][\x80-\xbf]|[\xe0-\xef][\x80-\xbf]{2}|[\xf0-\xff][\x80-\xbf]{3}/"; $re['gb2312'] = "/[\x01-\x7f]|[\xb0-\xf7][\xa0-\xfe]/"; $re['gbk'] = "/[\x01-\x7f]|[\x81-\xfe][\x40-\xfe]/"; $re['big5'] = "/[\x01-\x7f]|[\x81-\xfe]([\x40-\x7e]|\xa1-\xfe])/"; preg_match_all($re[$charset], $str, $match); $slice = join("", array_slice($match[0], $start, $length)); } return $suffix ? $slice . '...' : $slice; } function formatTime($time) { $rtime = date("m-d H:i", $time); $htime = date("H:i", $time); $time = time() - $time; if ($time < 60) { $str = '刚刚'; } elseif ($time < 60 * 60) { $min = floor($time / 60); $str = $min . '分钟前'; } elseif ($time < 60 * 60 * 24) { $h = floor($time / (60 * 60)); $str = $h . '小时前 '; } elseif ($time < 60 * 60 * 24 * 3) { $d = floor($time / (60 * 60 * 24)); if ($d == 1) { $str = '昨天 ' . date("H:i", $time); } else { $str = '前天 ' . date("H:i", $time); } } else { $str = $rtime; } return $str; } function format($time) { $t = NOW_TIME - $time; $mon = (int) ($t / (86400 * 30)); if ($mon >= 1) {return '一个月前';} $day = (int) ($t / 86400); if ($day >= 1) {return $day . '天前';} $h = (int) ($t / 3600); if ($h >= 1) {return $h . '小时前';} $min = (int) ($t / 60); if ($min >= 1){return $min . '分前';} return '刚刚'; } function getDates($time,$type = 1) { if($time > 0) { if($type == 0) { return date('Y-m-d H:i:s',$time); } else if($type == 1) { return date('Y-m-d H:i',$time); } else if($type == 2) { return date('Y-m-d',$time); } else if($type == 3) { return date('Y-m-d H:00',$time); } else if($type == 4) { return date('H:i',$time); } else if($type == 5) { return date('Y-m-d 00:00',$time); } else if($type == 6) { return date('Y-m-d H:i',$time); } } else { return "<span class='iconfont icon-nothing'></span>"; } } function getMenuTree($list =[], $pk='menu_id',$pid = 'parent_id',$child = 'childMenu',$star=0,$checkedMenuIds=[]) { $tree = array(); if(is_array($list)) { $menu = array(); foreach ($list as $k => &$v) { if(in_array($v[$pk],$checkedMenuIds)) { $v['checked'] = 'checked'; } $menu[$v[$pk]] = &$list[$k]; } foreach ($list as $k => &$v) { $parentId = $v[$pid]; if ($star == $parentId) { if($checkedMenuIds) { $tree[] = &$list[$k]; } else { $tree[$list[$k][$pk]] = &$list[$k]; } } else { if (isset($menu[$parentId])) { $parent = &$menu[$parentId]; if($checkedMenuIds) { $parent[$child][] = &$list[$k]; } else { $parent[$child][$list[$k][$pk]] = &$list[$k]; } } } } } return $tree; } function delFileByDir($dir) { $dh = opendir($dir); while ($file = readdir($dh)) { if ($file != "." && $file != "..") { $fullpath = $dir . "/" . $file; if (is_dir($fullpath)) { delFileByDir($fullpath); } else { unlink($fullpath); } } } closedir($dh); } function sendSMS($code = '',$name = '',$mobile = '',$title = '') { import('Org.Alidayu.top.TopClient'); import('Org.Alidayu.top.ResultSet'); import('Org.Alidayu.top.RequestCheckUtil'); import('Org.Alidayu.top.TopLogger'); import('Org.Alidayu.top.request.AlibabaAliqinFcSmsNumSendRequest'); $sms = new \TopClient; $sms->appkey = '23513210'; $sms->secretKey = '43c1745719702f06c849effb4dfeadc6'; $sms->format = "json"; $send = new \AlibabaAliqinFcSmsNumSendRequest; $send ->setExtend( "123456" ); $send ->setSmsType( "normal" ); $send ->setSmsFreeSignName( "FeelDesk" ); if($name) { $send ->setSmsParam( "{name:'{$name}'}" ); } if($title) { $send ->setSmsParam( "{title:'{$title}'}" ); } $send ->setRecNum($mobile); $send ->setSmsTemplateCode($code); $resp = $sms ->execute($send); return json_decode(json_encode($resp),true); } function getSmsRecord($mobile = '',$date = '',$p = 1) { import('Org.Alidayu.top.TopClient'); import('Org.Alidayu.top.ResultSet'); import('Org.Alidayu.top.RequestCheckUtil'); import('Org.Alidayu.top.TopLogger'); import('Org.Alidayu.top.request.AlibabaAliqinFcSmsNumQueryRequest'); $sms = new \TopClient; $sms->appkey = '23513210'; $sms->secretKey = '43c1745719702f06c849effb4dfeadc6'; $req = new AlibabaAliqinFcSmsNumQueryRequest; $req->setRecNum($mobile); $req->setQueryDate($date); $req->setCurrentPage("$p"); $req->setPageSize("5"); $resp = $sms->execute($req); return json_decode(json_encode($resp),true); } function sendMail($address, $name, $subject = '', $body = '',$attachment = null, $config = array()) { if(!$config) { $config = M('Mail')->where(['company_id' => 0])->find(); } vendor('PHPMailer.class#phpmailer'); $mail = new PHPMailer(); $mail->ClearAddresses(); $mail->IsSMTP(); $mail->CharSet = 'UTF-8'; $mail->SMTPAuth = true; $mail->SMTPDebug = false; if($config['send_port'] != 587) { $mail->SMTPSecure = 'ssl'; } else { $mail->SMTPSecure = 'tls'; } $mail->Host = $config['smtp']; $mail->Port = $config['send_port']; $mail->Username = $config['account']; $mail->Password = htmlspecialchars_decode($config['password']); $mail->SetFrom($config['from_email'], $config['from_name']); $replyEmail = $config['REPLY_EMAIL']?$config['REPLY_EMAIL']:$config['FROM_EMAIL']; $replyName = $config['REPLY_NAME']?$config['REPLY_NAME']:$config['FROM_NAME']; $mail->AddReplyTo($replyEmail, $replyName); $mail->Subject = $subject; $mail->AltBody = L('SEND_MAIL_ALT_BODY'); $mail->MsgHTML($body); $mail->AddAddress($address,$name); if(is_array($attachment)) { foreach ($attachment as $file) { is_file($file) && $mail->AddAttachment($file); } } return $mail->Send() ? 1 : $mail->ErrorInfo; } function createToken() { $code = chr(mt_rand(0xB0, 0xF7)) . chr(mt_rand(0xA1, 0xFE)) . chr(mt_rand(0xB0, 0xF7)) . chr(mt_rand(0xA1, 0xFE)) . chr(mt_rand(0xB0, 0xF7)) . chr(mt_rand(0xA1, 0xFE)); session('TOKEN', authcode($code)); } function checkToken($token) { if ($token == session('TOKEN')) { session('TOKEN', NULL); return TRUE; } else { return FALSE; } } function authcode($str,$key = "FeelDesk") { $str = substr(md5($str), 8, 10); return md5($key . $str); } function getAccessToken($cid,$key) { $code = chr(mt_rand(0xB0, 0xF7)) . $cid . chr(mt_rand(0xA1, 0xFE)) . chr(mt_rand(0xB0, 0xF7)) . chr(mt_rand(0xA1, 0xFE)) . chr(mt_rand(0xB0, 0xF7)) . chr(mt_rand(0xA1, 0xFE)); return authcode($code,$key); } function FEELDESK($action='',$params=[],$title='',$style='',$load='',$iconstyle='') { $user = session('index'); $class = $icon = ''; $hasAuth = D('RoleAuth')->checkRoleAuthByMenu($user['company_id'],$action,$user['role_id']); if($user['is_first'] == 1) { if(!$hasAuth) { $action = 'javascript:'; $title = L('UNAUTHORIZED'); $class = ' style=display:none'; } else if(!$action) { $action = 'javascript:'; } else { if($style) $class = ' class="'.$style.'"'; $action = U($action, $params); } } else { if($style) $class = ' class="'.$style.'"'; if(!$action) { $action = 'javascript:;'; } else { $action = U($action, $params); } } if($iconstyle) $icon = "class='{$iconstyle}'"; if($load) { $load = ' load="'.$load.'"'; } else { $load = ' load=loading'; } $a_tag = '<a href="'.$action.'"'.$class.$load.' ><i '.$icon.'></i>'.$title.'</a>'; return $a_tag; } function getTakingTime($begin_time,$end_time) { if($begin_time < $end_time) { $starttime = $begin_time; $endtime = $end_time; } else { $starttime = $end_time; $endtime = $begin_time; } $timediff = $endtime-$starttime; $days = intval($timediff/86400); $days = $days ? sprintf("%02d", $days) : 0; $remain = $timediff%86400; $hours = intval($remain/3600); $hours = $hours ? sprintf("%02d", $hours) : 0; $remain = $remain%3600; $mins = intval($remain/60); $mins = $mins ? sprintf("%02d", $mins) : 0; $secs = $remain%60; $secs = sprintf("%02d", $secs); $res = ["day" => $days,"hour" => $hours,"min" => $mins,"sec" => $secs]; return $res; } function getTakingTimeBySec($time) { if(is_numeric($time)) { $value = ['day'=>0,"hour" => 0, "min" => 0]; if($time >= 86400) { $value["day"] = floor($time/86400); $time = ($time%86400); } if($time >= 3600) { $value["hour"] = floor($time/3600); $time = ($time%3600); } if($time >= 60) { $value["min"] = floor($time/60); $time = ($time%60); } if(floor($time) > 0) { $value["min"] += 1; } return $value; } else { return 0; } } function getFileName($filename) { return substr($filename,0,strrpos($filename, '.')); } function Qiniu_Encode($str) { $find = array('+', '/'); $replace = array('-', '_'); return str_replace($find, $replace, base64_encode($str)); } function Qiniu_Sign($url) { $setting = M('qiniu')->where(['company_id'=>0])->find(); $duetime = NOW_TIME + 86400; $DownloadUrl = $url . '?e=' . $duetime; $Sign = hash_hmac ( 'sha1', $DownloadUrl, $setting['secrect_key'], true ); $EncodedSign = Qiniu_Encode ( $Sign ); $Token = $setting['access_key'] . ':' . $EncodedSign; $RealDownloadUrl = $DownloadUrl . '&token=' . $Token; return $RealDownloadUrl; } function HtmlClose($body) { $strlen_var = strlen($body); if (strpos($body, '<') === false) { return $body; } $html_tag = $size = 0; $summary_string = ''; $html_array_str = ''; $html_array = array('left' => array(), 'right' => array()); for($i = 0; $i < $strlen_var; ++$i) { $current_var = substr($body, $i, 1); if($current_var == '<') { $html_tag = 1; $html_array_str = ''; } else if($html_tag == 1) { if($current_var == '>') { $html_array_str = trim($html_array_str); if(substr($html_array_str, -1) != '/') { $f = substr($html_array_str, 0, 1); if($f == '/') { $html_array['right'][] = str_replace('/', '', $html_array_str); } else if ($f != '?') { if(strpos($html_array_str, ' ') !== false) { $html_array['left'][] = strtolower(current(explode(' ', $html_array_str, 2))); } else { $html_array['left'][] = strtolower($html_array_str); } } } $html_array_str = ''; $html_tag = 0; } else { $html_array_str .= $current_var; } } else { --$size; } $ord_var_c = ord($body{$i}); switch (true) { case (($ord_var_c & 0xE0) == 0xC0): $summary_string .= substr($body, $i, 2); $i += 1; break; case (($ord_var_c & 0xF0) == 0xE0): $summary_string .= substr($body, $i, 3); $i += 2; break; case (($ord_var_c & 0xF8) == 0xF0): $summary_string .= substr($body, $i, 4); $i += 3; break; case (($ord_var_c & 0xFC) == 0xF8): $summary_string .= substr($body, $i, 5); $i += 4; break; case (($ord_var_c & 0xFE) == 0xFC): $summary_string .= substr($body, $i, 6); $i += 5; break; default: $summary_string .= $current_var; } } if ($html_array['left']) { $html_array['left'] = array_reverse($html_array['left']); foreach ($html_array['left'] as $index => $tag) { $key = array_search($tag, $html_array['right']); if($key !== false) { unset($html_array['right'][$key]); } else { $summary_string .= '</' . $tag . '>'; } } } return $summary_string; } function getEncode($array) { $a = json_encode($array); return $a; } function remove_trim($str) { return rtrim($str,','); } function checkFields($data = array(), $fields = array()) { foreach ($data as $k => $val ) { if (!in_array($k, $fields)) { unset($data[$k]); } } return $data; } function CrmisUniqueData($type,$company_id,$form_id,$form_content) { $data = getCrmDbModel($type.'_detail')->where(['company_id'=>$company_id,'form_id'=>$form_id,'form_content'=>$form_content])->select(); $i = 0; foreach($data as $v) { $info = getCrmDbModel($type)->where(['company_id'=>$company_id,$type.'_id'=>$v[$type.'_id']])->find(); if($info) { $i++; } } if($i > 0) { return $info; } else { return false; } } function FEELCRM($action='',$params=[],$title='',$style='',$load='',$iconstyle='',$showtitle='') { $user = session('index'); $class = $icon = ''; $hasAuth = D('RoleAuth')->checkRoleAuthByMenu($user['company_id'],$action,$user['role_id'],'crm'); if($user['is_first'] == 1) { if(!$hasAuth) { $action = 'javascript:'; $title = L('UNAUTHORIZED'); $class = ' style=display:none'; } else if(!$action) { $action = 'javascript:'; } else { if($style) $class = ' class="'.$style.'"'; $action = U($action, $params); } } else { if($style) $class = ' class="'.$style.'"'; if(!$action) { $action = 'javascript:'; } else { $action = U($action, $params); } } if($iconstyle) $icon = "class='{$iconstyle}'"; if($load) $load = ' load="'.$load.'"'; $a_tag = '<a href="'.$action.'"'.$class.$load.' title="'.$showtitle.'" ><i '.$icon.'></i>'.$title.'</a>'; return $a_tag; } function CrmfetchAll($data,$field) { $datas = []; foreach($data as $v) { $datas[$v[$field]] = $v; } return $datas; } function CrmisLoginTimeout($login_time,$setTime) { session('[start]'); $loginTimes = intval((NOW_TIME - $login_time)/60); if($loginTimes > (int) $setTime) { session('index',null); header('Location: ' . U('Index/login/index')); exit(); } } function CrmgetPercentage($totle,$num) { if($totle == 0 || !$totle) { return '0%'; } else { return number_format(($num/$totle)*100,2).'%'; } } function CrmgetViewName() { $url = CONTROLLER_NAME.'/'.ACTION_NAME; $viewName = D('Menu')->getNameByLang('menu_name'); $view_name = M('menu')->where(['menu_action'=>$url,'apply'=>10])->getField("{$viewName}"); return $view_name; } function CrmgetRecordContent($str = '') { $contentArr = explode('<br/>',$str); $content = ''; foreach($contentArr as $k=>$v) { if(!$v) { unset($contentArr[$k]); continue; } else { $style = 'color:#333;'; if(mb_substr($v, 0, 4,'utf-8') == '对话开始') { $style = 'color:#999;font-size:14px;'; $v = str_replace($v,"<div style='margin-bottom: 10px;'>$v</div>",$v); } else if(mb_substr($v, 0, 4,'utf-8') == '对话结束') { $style = 'color:#999;font-size:14px;'; $v = str_replace($v,"<div style='margin-bottom: 10px;'>$v</div>",$v); } else if($k+1 == count($contentArr)) { $style = 'color:red;font-size:14px;'; $v = str_replace($v,"<div style='margin-top: 10px;'>对话结束原因：{$v}</div>",$v); } else { $role = mb_substr($v, 2, 1,'utf-8'); if($role == '>') $v = str_replace('>',"<span style='margin-right: 10px;'></span>",$v); $role = mb_substr($v, 0, 2,'utf-8'); if($role == '系统') { $style = 'color:#999;'; $v = str_replace($role,"<span style='font-weight: bold'>{$role}</span>",$v); } else if($role == '客服') { $style = 'color:#3b8ed3;'; $v = str_replace($role,"<span style='font-weight: bold'>{$role}</span>",$v); } else if($role == '访客') { $style = 'color:#42b475;'; $v = str_replace($role,"<span style='font-weight: bold'>{$role}</span>",$v); } else { $v = str_replace($v,"<div style='margin-bottom: 10px;'>$v</div>",$v); } } $content .= "<div style='padding:0 15px 0 30px;font-size:14px;".$style."'>{$v}</div>"; } } return $content; } function CrmgetMemberGroupName($groups,$memberGroupIds) { $groupNameStr = ''; foreach($groups as $v) { if(in_array($v['group_id'],explode(',',$memberGroupIds))) { $groupNameStr .= $v['group_name'].'、'; } } if(!$groupNameStr) { $groupNameStr = '<span class="iconfont icon-nothing gray1"></span>'; } return rtrim($groupNameStr,'、'); } function CrmgetCrmDetailList($type,$get_id,$company_id,$formName='') { $data = []; $crmsite = getCrmDbModel('Setting')->where(['company_id'=>$company_id])->find(); $crmsite = unserialize($crmsite['value']); if($formName) { $form = getCrmDbModel('define_form')->where(['company_id'=>$company_id,'closed'=>0,'type'=>$type,'form_name'=>['in',$formName]])->field('form_id,form_name,form_type')->select(); } else { $form = getCrmDbModel('define_form')->where(['company_id'=>$company_id,'closed'=>0,'type'=>$type])->field('form_id,form_name,form_type')->select(); } foreach($form as $k1=>&$v1) { $form_content= getCrmDbModel($type.'_detail') ->where(['company_id'=>$company_id,$type.'_id'=>$get_id,'form_id'=>$v1['form_id']]) ->getField('form_content'); if($v1['form_type'] == 'textarea') { $data[$v1['form_name']] = htmlspecialchars_decode($form_content); } elseif($v1['form_type'] == 'region') { if($form_content) { $region_detail = explode(',',$form_content); $form_content = ''; if($region_detail[0]) { $name = getCrmLanguageData('name'); $country = getCrmDbModel('country')->where(['code'=>$region_detail[0]])->getField($name); if(!$crmsite['regionType'] || $crmsite['regionType'] == 'world') { $form_content .= $country; } } if($region_detail[0] && $region_detail[1]) { $province_name = getCrmLanguageData('name'); $province = getCrmDbModel('province') ->where(['code'=>$region_detail[1],'country_code'=>$region_detail[0]]) ->getField($province_name); if(!$crmsite['regionType'] || $crmsite['regionType'] == 'world') { $form_content .= '--'.$province; } else { $form_content .= $province; } } if($region_detail[0] && $region_detail[1] && $region_detail[2]) { $city_name = getCrmLanguageData('name'); $city = getCrmDbModel('city') ->where(['code'=>$region_detail[2],'country_code'=>$region_detail[0],'province_code'=>$region_detail[1]]) ->getField($city_name); $form_content .= '--'.$city; } if($region_detail[0] && $region_detail[1] && $region_detail[2] && $region_detail[3]) { $area_name = getCrmLanguageData('name'); $area = getCrmDbModel('area') ->where(['code'=>$region_detail[3],'country_code'=>$region_detail[0],'province_code'=>$region_detail[1],'city_code'=>$region_detail[2]]) ->getField($area_name); $form_content .= '--'.$area; } if(!$country && !$province && !$city) { $form_content = ''; for($i=0;$i<count($region_detail);$i++) { $region_content = explode('_',$region_detail[$i]); if($i >0) $form_content .= '--'; $form_content .= $region_content[0]; } } } $data[$v1['form_name']] = $form_content; } else { $data[$v1['form_name']] = $form_content; } } return $data; } function getGroupMemberList($company_id,$member_id) { $groupIds = M('member')->where(['member_id'=>$member_id])->getField('group_id'); foreach(explode(',',$groupIds) as $k=>$v) { $members[$k] = M('member') ->where(["find_in_set('{$v}',group_id)",'type'=>1,'company_id'=>$company_id]) ->field('member_id,name,group_id')->select(); } $membersId = []; $j = 0; foreach($members as $k1=>$v1) { foreach($v1 as $k2=>$v2) { if(!in_array($v2['member_id'],$membersId)) { $membersId[$j] = $v2['member_id']; $users[$j] = ['member_id'=>$v2['member_id'],'name'=>$v2['name']]; $j ++; } } } return ['member_id'=>$membersId,'user'=>$users]; } function getGroupMemberByGroups($company_id,$groupIds) { if(!is_array($groupIds)) { $groupIds = explode(',',$groupIds); } foreach($groupIds as $k=>$v) { $members[$k] = M('member') ->where(["find_in_set('{$v}',group_id)",'type'=>1,'closed'=>0,'feelec_opened'=>10,'company_id'=>$company_id]) ->field('member_id,name,group_id')->select(); } $membersId = []; $j = 0; foreach($members as $k1=>$v1) { foreach($v1 as $k2=>$v2) { if(!in_array($v2['member_id'],$membersId)) { $membersId[$j] = $v2['member_id']; $users[$j] = ['member_id'=>$v2['member_id'],'name'=>$v2['name'],'id'=>$v2['member_id']]; $j ++; } } } return ['member_id'=>$membersId,'user'=>$users]; } function CrmmemberRoleCrmauth($thisMember,$company_id,$member_id,$viewType='',$showtype='index') { if($showtype == 'pool') { $all_view_auth = D('RoleAuth')->checkRoleAuthByMenu($company_id,'poolAll',$thisMember['role_id'],'crm'); $group_view_auth = D('RoleAuth')->checkRoleAuthByMenu($company_id,'poolGroup',$thisMember['role_id'],'crm'); $own_view_auth = D('RoleAuth')->checkRoleAuthByMenu($company_id,'poolOwn',$thisMember['role_id'],'crm'); } elseif($showtype == 'clue') { $all_view_auth = D('RoleAuth')->checkRoleAuthByMenu($company_id,'clueAll',$thisMember['role_id'],'crm'); $group_view_auth = D('RoleAuth')->checkRoleAuthByMenu($company_id,'clueGroup',$thisMember['role_id'],'crm'); $own_view_auth = D('RoleAuth')->checkRoleAuthByMenu($company_id,'clueOwn',$thisMember['role_id'],'crm'); } elseif($showtype == 'cluePool') { $all_view_auth = D('RoleAuth')->checkRoleAuthByMenu($company_id,'cluePoolAll',$thisMember['role_id'],'crm'); $group_view_auth = D('RoleAuth')->checkRoleAuthByMenu($company_id,'cluePoolGroup',$thisMember['role_id'],'crm'); $own_view_auth = D('RoleAuth')->checkRoleAuthByMenu($company_id,'cluePoolOwn',$thisMember['role_id'],'crm'); } elseif($showtype == 'contract') { $all_view_auth = D('RoleAuth')->checkRoleAuthByMenu($company_id,'contractsAll',$thisMember['role_id'],'crm'); $group_view_auth = D('RoleAuth')->checkRoleAuthByMenu($company_id,'contractsGroup',$thisMember['role_id'],'crm'); $own_view_auth = D('RoleAuth')->checkRoleAuthByMenu($company_id,'contractsOwn',$thisMember['role_id'],'crm'); } elseif($showtype == 'account') { $all_view_auth = D('RoleAuth')->checkRoleAuthByMenu($company_id,'accountAll',$thisMember['role_id'],'crm'); $group_view_auth = D('RoleAuth')->checkRoleAuthByMenu($company_id,'accountGroup',$thisMember['role_id'],'crm'); $own_view_auth = D('RoleAuth')->checkRoleAuthByMenu($company_id,'accountOwn',$thisMember['role_id'],'crm'); } elseif($showtype == 'receipt') { $all_view_auth = D('RoleAuth')->checkRoleAuthByMenu($company_id,'receiptAll',$thisMember['role_id'],'crm'); $group_view_auth = D('RoleAuth')->checkRoleAuthByMenu($company_id,'receiptGroup',$thisMember['role_id'],'crm'); $own_view_auth = D('RoleAuth')->checkRoleAuthByMenu($company_id,'receiptOwn',$thisMember['role_id'],'crm'); } elseif($showtype == 'invoice') { $all_view_auth = D('RoleAuth')->checkRoleAuthByMenu($company_id,'invoiceAll',$thisMember['role_id'],'crm'); $group_view_auth = D('RoleAuth')->checkRoleAuthByMenu($company_id,'invoiceGroup',$thisMember['role_id'],'crm'); $own_view_auth = D('RoleAuth')->checkRoleAuthByMenu($company_id,'invoiceOwn',$thisMember['role_id'],'crm'); } else { $all_view_auth = D('RoleAuth')->checkRoleAuthByMenu($company_id,'all',$thisMember['role_id'],'crm'); $group_view_auth = D('RoleAuth')->checkRoleAuthByMenu($company_id,'group',$thisMember['role_id'],'crm'); $own_view_auth = D('RoleAuth')->checkRoleAuthByMenu($company_id,'own',$thisMember['role_id'],'crm'); } $users = $members = []; if(!$viewType) { if($all_view_auth) { $members = M('member')->where(['type'=>1,'company_id'=>$company_id])->field('member_id,name')->select(); $users = M('member')->where(['type'=>1,'company_id'=>$company_id,'closed'=>0])->field('member_id,name')->select(); $memberIds = []; foreach($members as $k=>$m) { $memberIds[$k] = $m['member_id']; } if($showtype == 'pool' || $showtype == 'cluePool') { $field = ['exp','is not null']; } else { $field = ['in',implode(',',$memberIds)]; } } else if($group_view_auth) { $groupIds = M('member')->where(['member_id'=>$member_id])->getField('group_id'); foreach(explode(',',$groupIds) as $k=>$v) { $members[$k] = M('member') ->where(["find_in_set('{$v}',group_id)",'type'=>1,'company_id'=>$company_id]) ->field('member_id,name,group_id')->select(); } $membersId = []; $j = 0; foreach($members as $k1=>$v1) { foreach($v1 as $k2=>$v2) { if(!in_array($v2['member_id'],$membersId)) { $membersId[$j] = $v2['member_id']; if($v2['closed'] == 0) { $users[$j] = ['member_id'=>$v2['member_id'],'name'=>$v2['name']]; } $j ++; } } } $field = ['in',implode(',',$membersId)]; } else { if(!$own_view_auth) { $field = 0; } else { $users[0] = ['member_id'=>$member_id,'name'=>$thisMember['name']]; $field = $member_id; } } return $field; } else { if($viewType == 'all') { $members = M('member')->where(['type'=>1,'company_id'=>$company_id])->field('member_id,name')->select(); $users = M('member')->where(['type'=>1,'company_id'=>$company_id,'closed'=>0])->field('member_id,name')->select(); $memberIds = []; foreach($members as $k=>$m) { $memberIds[$k] = $m['member_id']; } if($showtype == 'pool' || $showtype == 'cluePool') { $field = ['exp','is not null']; } else { $field = ['in',implode(',',$memberIds)]; } } else if($viewType == 'group') { $groupIds = M('member')->where(['member_id'=>$member_id])->getField('group_id'); foreach(explode(',',$groupIds) as $k=>$v) { $members[$k] = M('member') ->where(["find_in_set('{$v}',group_id)",'type'=>1,'company_id'=>$company_id]) ->field('member_id,name,group_id,closed')->select(); } $membersId = []; $j = 0; foreach($members as $k1=>$v1) { foreach($v1 as $k2=>$v2) { if(!in_array($v2['member_id'],$membersId)) { $membersId[$j] = $v2['member_id']; if($v2['closed'] == 0) { $users[$j] = ['member_id'=>$v2['member_id'],'name'=>$v2['name']]; } $j++; } } } $field = ['in',implode(',',$membersId)]; } else { if(!$own_view_auth) { $field = 0; $users = ''; } else { $users[0] = ['member_id'=>$member_id,'name'=>$thisMember['name']]; $field = $member_id; } } return ['field'=>$field,'users'=>$users,'members'=>$members]; } } function CrmgetDefineFormField($company_id,$type,$form_name,$keyword) { $name_form_id = getCrmDbModel('define_form') ->where(['company_id'=>$company_id,'type'=>$type,'form_name'=>['in',$form_name]]) ->field('form_id,form_type')->select(); $data_arr = []; foreach($name_form_id as $namev) { if(in_array($name_form_id['form_type'],['radio','select'])) { $form_content_field = $keyword; } else { $form_content_field = ["like","%".$keyword."%"]; } $data_name = getCrmDbModel($type.'_detail')->where(['company_id'=>$company_id,'form_id'=>$namev['form_id'],'form_content'=>$form_content_field])->field($type.'_id,form_content')->select(); foreach($data_name as $cv) { $data_arr[] .= $cv[$type.'_id']; } } $data_arr = array_unique($data_arr); if(count($data_arr) > 0) { $field = implode(',',$data_arr); } else { $field = 0; } return $field; } function CrmgetDefineFormHighField($company_id,$type,$form_name,$keyword) { $name_form_id = getCrmDbModel('define_form') ->where(['company_id'=>$company_id,'type'=>$type,'form_name'=>['in',$form_name]]) ->field('form_id,form_type')->find(); if($keyword) { if(in_array($name_form_id['form_type'],['radio','select'])) { $form_content_field = ['in',$keyword]; } else { $form_content_field = ["like","%".$keyword."%"]; } $data_name = getCrmDbModel($type.'_detail')->where(['company_id'=>$company_id,'form_id'=>$name_form_id['form_id'],'form_content'=>$form_content_field])->field($type.'_id,form_content')->select(); } else { $data_name = getCrmDbModel($type.'_detail')->where(['company_id'=>$company_id,'form_id'=>$name_form_id['form_id'],'form_content'=>''])->field($type.'_id,form_content')->select(); } foreach($data_name as $cv) { $data_arr[] .= $cv[$type.'_id']; } if(count($data_arr) > 0) { return $data_arr; } else { return false; } } function CrmgetDefineFormHighFieldTimeRange($company_id,$type,$form_name,$starttime,$endtime='') { $name_form_id = getCrmDbModel('define_form') ->where(['company_id'=>$company_id,'type'=>$type,'form_name'=>['in',$form_name]]) ->field('form_id,form_type')->find(); if($starttime) { $starttime = date('Y-m-d H:i:s',$starttime); if($endtime) { $endtime = date('Y-m-d H:i:s',$endtime); $form_content_field = [['egt',$starttime],['elt',$endtime]]; } else { $form_content_field = [['egt',$starttime],['elt',date('Y-m-d H:i:s',time())]]; } $data_name = getCrmDbModel($type.'_detail')->where(['company_id'=>$company_id,'form_id'=>$name_form_id['form_id'],'form_content'=>$form_content_field])->field($type.'_id,form_content')->select(); } else { $data_name = getCrmDbModel($type.'_detail')->where(['company_id'=>$company_id,'form_id'=>$name_form_id['form_id'],'form_content'=>''])->field($type.'_id,form_content')->select(); } foreach($data_name as $cv) { $data_arr[] .= $cv[$type.'_id']; } if(count($data_arr) > 0) { return $data_arr; } else { return false; } } function CrmgetShowListField($type,$company_id) { $lang = cookie('think_language'); $name = 'form_description'; if($lang == 'en-us') $name = 'name_en as form_description'; if($lang == 'ja-jp') $name = 'name_jp as form_description'; $field = getCrmDbModel('define_form')->where(['company_id'=>$company_id,'closed'=>0,'type'=>$type,'show_list'=>1]) ->field('form_name,'.$name.',form_type,role_id,member_id')->order('orderby asc')->select(); $form_name = []; foreach($field as $val) { $form_name[] = $val['form_name']; } $form_name = implode(',',$form_name); return ['form_name'=>$form_name,'form_list'=>$field]; } function CrmgetFieldName($id,$type) { $company_id = getCrmDbModel($type)->where([$type.'_id'=>$id,'isvalid'=>1])->getField('company_id'); $detail = CrmgetCrmDetailList($type,$id,$company_id,'name'); return $detail['name']; } function get_weeks($daynum = 7,$time = '', $format='Y-m-d') { $time = $time != '' ? $time : time(); $date = []; for ($i=1; $i<=$daynum; $i++){ $date[$i] = date($format ,strtotime( '+' . $i-$daynum .' days', $time)); } return $date; } function resultCategory($data,$class='',$type_id = 0,$j=0) { $i = 1; $j ++; $count = count($data); $arr = ''; foreach($data as $key=>$val) { $padding = $j * 3; $paddingstr = "padding: 0 ".$padding."%"; $prolink = U('AjaxRequest/getProductList',['id'=>encrypt($val['type_id'],'PRODUCT')]); if(count($val['subClass']) > 0 && $class=='parent') { $arr .= '<div class="product-parent-item" data-value="'.$val['type_id'].'" data-name="'.$val['type_name'].'"><div class="product-parent-name product-type"><span>'.$val['type_name'].'</span><div class="operate"><i class="iconfont icon-tianjia to-child"></i><i class="iconfont icon-more"></i><ul class="operate-menu"><li class="to-product" data-href="'.$prolink.'" data-value="'.$val['type_id'].'">'.L('PRODUCT').'</li></ul></div></div><ul class="product-child-item">'; } else { if(count($val['subClass']) > 0 && $class == 'child') { $arr .='<li class="product-child-type" data-value="'.$val['type_id'].'" data-name="'.$val['type_name'].'"><div class="product-type" style="'.$paddingstr.'"><i class="iconfont icon-wenjian"></i><div class="product-child-name">'.$val['type_name'].'</div><div class="operate"><i class="iconfont icon-tianjia to-child"></i><i class="iconfont icon-more"></i><ul class="operate-menu"><li class="to-product" data-href="'.$prolink.'" data-value="'.$val['type_id'].'">'.L('PRODUCT').'</li></ul></div></div><ul class="product-child-item">'; } elseif($class == 'parent') { $arr .= '<div class="product-parent-item" data-value="'.$val['type_id'].'" data-name="'.$val['type_name'].'"><div class="product-parent-name product-type"><span>'.$val['type_name'].'</span><div class="operate"><i class="iconfont icon-more"></i><ul class="operate-menu"><li class="to-product" data-href="'.$prolink.'" data-value="'.$val['type_id'].'">'.L('PRODUCT').'</li></ul></div></div>'; } else { $arr .='<li class="product-child-type" data-value="'.$val['type_id'].'" data-name="'.$val['type_name'].'"><div class="product-type" style="'.$paddingstr.'"><i class="iconfont icon-wenjian"></i><div class="product-child-name">'.$val['type_name'].'</div><div class="operate"><i class="iconfont icon-more"></i><ul class="operate-menu"><li class="to-product" data-href="'.$prolink.'" data-value="'.$val['type_id'].'">'.L('PRODUCT').'</li></ul></div></div>'; } } if($val['subClass']) { $arr .= resultCategory($val['subClass'],'child',$type_id,$j); } if(count($val['subClass']) > 0 && $class=='parent') { $arr .= '</ul></div>'; } else { if(count($val['subClass']) > 0 && $class == 'child') { $arr .= '</ul></li>'; } elseif($class == 'parent') { $arr .= '</div>'; } else { $arr .= '</li>'; } } $i++; } return $arr; } function tocurl($url, $header,$content='',$method='POST'){ $curl = curl_init(); curl_setopt($curl, CURLOPT_URL, $url); curl_setopt($curl, CURLOPT_RETURNTRANSFER,1); curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false); $timeout = 30; curl_setopt($curl, CURLOPT_CONNECTTIMEOUT, $timeout); curl_setopt($curl,CURLOPT_POST,1); curl_setopt($curl, CURLOPT_HTTPHEADER, $header); curl_setopt($curl, CURLOPT_HEADER, false); if($method == 'GET') { curl_setopt($curl, CURLOPT_CUSTOMREQUEST, "GET"); curl_setopt($curl, CURLOPT_HTTPGET, 1); } else { curl_setopt($curl, CURLOPT_CUSTOMREQUEST, "POST"); curl_setopt($curl, CURLOPT_POSTFIELDS,$content); } $data = curl_exec($curl); $status = curl_getinfo($curl, CURLINFO_HTTP_CODE); $lasturl = curl_getinfo($curl,CURLINFO_EFFECTIVE_URL); curl_close($curl); $res = json_decode($data,true); return $res; } function imgToBase64($img_file) { $img_base64 = ''; if (file_exists($img_file)) { $app_img_file = $img_file; $img_info = getimagesize($app_img_file); $fp = fopen($app_img_file, "r"); if ($fp) { $filesize = filesize($app_img_file); $content = fread($fp, $filesize); $file_content = chunk_split(base64_encode($content)); switch ($img_info[2]) { case 1: $img_type = "gif"; break; case 2: $img_type = "jpg"; break; case 3: $img_type = "png"; break; } $img_base64 = 'data:image/' . $img_type . ';base64,' . $file_content; } fclose($fp); } return $img_base64; } function a_array_unique($array){ $out = array(); foreach ($array as $key=>$value) { if (!in_array($value, $out)){ $out[$key] = $value; } } $out = array_values($out); return $out; } function getReceiptTypeName($type) { switch($type) { case 'CASH': $name = L('CASH'); break; case 'BANK': $name = L('BANK_TRANSFER'); break; case 'CORPORATE': $name = L('CORPORATE_TRANSFER'); break; case 'CHEQUE': $name = L('CHEQUE'); break; case 'REMIT': $name = L('REMITTANCE'); break; case 'WECHAT': $name = L('WECHAT_TRANSFER'); break; case 'ALIPAY': $name = L('ALIPAY_TRANSFER'); break; case 'ESCROW': $name = L('THIRD_PARTY_PAYMENT'); break; } return $name; } function getFinanceExamineName($status,$type='') { if($type == 'html') { switch($status) { case '1': $name = '<span class="orange">'.L('WAIT_AUDIT').'</span>'; break; case '-1': $name = '<span class="red1">'.L('REJECTED').'</span>'; break; case '2': $name = '<span class="green1">'.L('AUDITED').'</span>'; break; } } elseif($type == 'operate') { switch($status) { case 'examine': $name = L('AUDIT'); break; case 'reject': $name = L('REJECT'); break; case 'revoke': $name = L('REVOKE'); break; } } elseif($type == 'operate_result') { switch($status) { case 'examine': $name = L('WAIT_AUDIT'); break; case 'reject': $name = L('REJECTED'); break; case 'revoke': $name = L('REVOKED'); break; } } else { switch($status) { case '1': $name = L('WAIT_AUDIT'); break; case '-1': $name = L('REJECTED'); break; case '2': $name = L('AUDITED'); break; } } return $name; } function getInvoiceTypeName($type) { switch($type) { case 'GENERAL': $name = L('VAT_GENERAL_INVOICE'); break; case 'SPECIAL': $name = L('VALUE_ADDED_TAX_INVOICE'); break; case 'RECEIPT': $name = L('RECEIPT'); break; } return $name; } function getLanguage($company = []) { $language = M('language')->select(); if($company) { foreach($language as $k=>$v) { if($v['lang'] == 'en-us' && $company['en_auth'] != 10) unset($language[$k]); if($v['lang'] == 'ja-jp' && $company['jp_auth'] != 10) unset($language[$k]); } } return $language; } function getCustomerCreateName($creater_id,$create_name='',$company_id=0,$type='') { if($type == 'html') { if (!$creater_id) { $html = '<span class="red1">'.L('SYSTEM_').'</span>'; }elseif ($creater_id == -1) { $html = '<span class="red1">'.L('THIRD_PARTY_SYSTEM').'</span>'; } elseif ($creater_id == -2) { $html = '<span class="red1">'.L('WEBSITE_REGIST').'</span>'; } elseif ($creater_id == -3) { $html = '<span class="red1">'.L('WEBSITE_REGIST').'('.L('CUSTOMER_SERVICE').')</span>'; } elseif ($creater_id == -4) { $html = '<span class="red1">'.L('WEBSITE_REGIST').'('.L('DISPATCH').')</span>'; } elseif ($creater_id == -5) { $html = '<span class="red1">'.L('WEBSITE_REGIST').'( CRM )</span>'; } elseif ($creater_id == -6) { $html = '<span class="red1">'.L('WEBSITE_REGIST').'('.L('TICKET').'5.0)</span>'; } elseif ($creater_id == -7) { $html = '<span class="red1">'.L('WEBSITE_REGIST').'('.L('BUSINESS_CARD').')</span>'; } else { if (!$create_name) { $create_name = M('Member')->where(['company_id' => $company_id, 'closed' => 0, 'type' => 1, 'member_id' => $creater_id])->getField('name'); } $html = '<span class="blue8">'.$create_name.' </span>'; } } else { if (!$creater_id) { $html = L('SYSTEM_'); }elseif ($creater_id == -1) { $html = L('THIRD_PARTY_SYSTEM'); } elseif ($creater_id == -2) { $html = L('WEBSITE_REGIST'); } elseif ($creater_id == -3) { $html = L('WEBSITE_REGIST').'('.L('CUSTOMER_SERVICE').')'; } elseif ($creater_id == -4) { $html = L('WEBSITE_REGIST').'('.L('DISPATCH').')'; } elseif ($creater_id == -5) { $html = L('WEBSITE_REGIST').'( CRM )'; } elseif ($creater_id == -6) { $html = L('WEBSITE_REGIST').'( '.L('TICKET').'5.0 )'; } elseif ($creater_id == -7) { $html = L('WEBSITE_REGIST').'( '.L('BUSINESS_CARD').' )'; }else { if (!$create_name) { $create_name = M('Member')->where(['company_id' => $company_id, 'closed' => 0, 'type' => 1, 'member_id' => $creater_id])->getField('name'); } $html = $create_name; } } return $html; } function getGroupCategory($data,$company_id,$type = 0,$parent_id = 0,$lev = 0) { $i = 1; $count = count($data); $members = D('Member')->where(['company_id'=>$company_id,'type'=>1,'closed'=>0])->field('member_id,name')->fetchAll(); $roles = D('Role')->where(['company_id'=>$company_id,'closed'=>0])->field('role_id,role_name')->fetchAll(); foreach($data as $key=>$val) { if($lev > 0) { $pre = ''; for($j = 1;$j<=$lev;$j++) { $pre .= '&nbsp;&nbsp;&nbsp;&nbsp;'; } } if($type == 1) { $html = ''; $html = '<tr><td class="left">'; $html .= '<span>'.$pre.$val['group_name'].'</span>'; if($val['is_default'] == '20') { $html .= '<i class="iconfont icon-moren orange5 fts25"></i>'; } $html .= '</td>'; if($members[$val['manager_id']]['name']) { $html .= '<td><span>'.$members[$val['manager_id']]['name'].'</span></td>'; } else { $html .= '<td><span><i class="iconfont icon-nothing"></i></span></td>'; } if($roles[$val['role_id']]['role_name']) { $html .= '<td><span>'.$roles[$val['role_id']]['role_name'].'</span></td>'; } else { $html .= '<td><span><i class="iconfont icon-nothing"></i></span></td>'; } $html .= '<td>'; if($val['closed'] == 0) { $html .= '<span class="open-status enable">'.L('ENABLE').'</span>'; } else { $html .= '<span class="open-status disable">'.L('DISABLE').'</span>'; } $html .= '</td>'; $html .= '<td class="listOperate">'; $html .= '<i class="iconfont icon-dian"></i>'; $html .= '<div class="operate hidden">'; $html .= FEELDESK('Group/edit',['group_id'=>encrypt($val['group_id'],'GROUP')],L('EDITOR'),'editBtn'); if($val['closed'] == 1) { $html .= FEELDESK('Group/delete',['id'=>$val['group_id']],L('DELETE'),'','del-group'); } $html .= FEELDESK('Member/index',['group_id'=>$val['group_id']],L('VIEW').L('USER'),'editBtn'); $html .= '<a href="javascript:" data-value="'.$val['group_id'].'" data-name="'.$val['group_name'].'" class="assign-user">'.L('ASSIGN_USER').'</a>'; $html .= '</div>'; $html .= '</td>'; $html .= '</tr>'; $arr[] = $html; } else { if($parent_id == $val['group_id']) { $arr[] = '<option value="'.$val['group_id'].'" selected >'.$pre.$val['group_name'].'</option>'; } else { $arr[] = '<option value="'.$val['group_id'].'" >'.$pre.$val['group_name'].'</option>'; } } if($val['subClass']) { $arr = array_merge($arr,getGroupCategory($val['subClass'],$company_id,$type,$parent_id,$lev+1)); } $i++; } return $arr; } function getNextMonth($timestamp) { $arr=getdate($timestamp); if($arr['mon'] == 12) { $year=$arr['year'] +1; $month=$arr['mon'] -11; $next_month = $year.'-'.$month; } else { $next_month = date('Y',$timestamp).'-'.(date('m',$timestamp)+1); } $next_month = date('Y-m',strtotime($next_month)); return $next_month; } function getLastMonth($timestamp) { $arr=getdate($timestamp); if($arr['mon'] == 1) { $year=$arr['year'] -1; $month=$arr['mon'] +11; $last_month = $year.'-'.$month; } else { $last_month = date('Y',$timestamp).'-'.(date('m',$timestamp)-1); } $last_month = date('Y-m',strtotime($last_month)); return $last_month; } function getKpiTypeName($type) { if($type == 'customer') { $name = L('FOLLOW_UP_WITH_CUSTOMERS'); } elseif($type == 'customer_trade') { $name = L('RANSACTION_CUSTOMER'); } elseif($type == 'contract') { $name = L('SIGNING_THE_CONTRACT'); } elseif($type == 'contract_money') { $name = L('CONTRACT_AMOUNT'); } elseif($type == 'receipt') { $name = L('AMOUNT_RECEIVED'); } return $name; } function curlJson($url,$data) { $data = json_encode($data); $curl = curl_init(); curl_setopt($curl, CURLOPT_URL, $url); curl_setopt($curl, CURLOPT_RETURNTRANSFER,1); curl_setopt($curl, CURLOPT_HTTPHEADER, ["Content-type: application/json"]); curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false); $timeout = 30; curl_setopt ($curl, CURLOPT_CONNECTTIMEOUT, $timeout); curl_setopt($curl,CURLOPT_POST,1); curl_setopt($curl, CURLOPT_HEADER, false); curl_setopt($curl, CURLOPT_CUSTOMREQUEST, "POST"); curl_setopt($curl, CURLOPT_POSTFIELDS,$data); $curlData = curl_exec($curl); curl_close($curl); $res = json_decode($curlData,true); return $res; } function getClueStatusName($status,$type = '') { if($type == 'html') { if($status == 2) { $name = "<span class='blue8'>".L('CONVERTED')."</span>"; } elseif($status == 1) { $name = "<span class='green1'>".L('FOLLOWING_UP')."</span>"; } else { $name = "<span class='yellow2'>".L('NOT_FOLLOWED_UP')."</span>"; } } else { if($status == 2) { $name = L('CONVERTED'); } elseif($status == 1) { $name = L('FOLLOWING_UP'); } else { $name = L('NOT_FOLLOWED_UP'); } } return $name; } function getCrmEntryMethod($type) { switch ($type) { case 'CREATE': $name = L('MANUAL_ENTRY'); break; case 'API': $name = L('API_INPUT'); break; case 'IMPORT': $name = L('BATCH_IMPORT'); break; } return $name; } function openFile($link,$type) { if($type == 'doc' || $type =='docx' || $type =='xlsx' || $type =='xls' || $type =='ppt' || $type =='pptx') { $link = 'https://view.officeapps.live.com/op/view.aspx?src='.$link; } return $link; } function getCreaterViewSql($member_id) { if(count($member_id) > 1) { if(is_array($member_id[1])) { $member_id[1] = implode(',',$member_id[1]); } $create_view_sql = "((member_id in (".$member_id[1].") or creater_id in (".$member_id[1].")) and member_id > 0)"; } else { $create_view_sql = "((member_id = ".$member_id." or creater_id = ".$member_id.") and member_id > 0)"; } return $create_view_sql; } function checkContacterSqlField($company_id,$contacterField) { if($contacterField) { $first_contacts = getCrmDbModel('contacter')->where(['company_id'=>$company_id,'isvalid'=>1,'contacter_id'=>['in',$contacterField]])->field('contacter_id')->select(); if($first_contacts) { $first_contact_ids = array_column($first_contacts,'contacter_id'); $contacterField = implode(',',$first_contact_ids); } else { $contacterField = 0; } } return $contacterField; } function getTypeIdByImportValue($company_id,$type_arr,$product_type,$lev = 0) { if(!$type_arr) { return false; } else { $type_id = $product_type[$type_arr[$lev]]['type_id']; if(!$type_id) { return false; } else { if($lev == (count($type_arr) - 1)) { return $type_id; } else { $type_id = getTypeIdByImportValue($company_id,$type_arr,$product_type[$type_arr[$lev]]['subClass'],$lev + 1); return $type_id; } } } } function CrmfetchAllChild($data,$field) { $datas = []; foreach($data as $v) { $datas[$v[$field]] = $v; if($v['subClass']) { $datas[$v[$field]]['subClass'] = CrmfetchAllChild($v['subClass'],$field); } } return $datas; } function updateFeelecPrimary($feelec_primary,$company_id) { if($feelec_primary == 10) { M('company')->where(['feelec_primary'=>10,'company_id'=>['neq',$company_id]])->save(['feelec_primary'=>20]); } }}namespace Think{ class Hook { static private $tags = array(); static public function add($tag,$name) { if(!isset(self::$tags[$tag])){ self::$tags[$tag] = array(); } if(is_array($name)){ self::$tags[$tag] = array_merge(self::$tags[$tag],$name); }else{ self::$tags[$tag][] = $name; } } static public function import($data,$recursive=true) { if(!$recursive){ self::$tags = array_merge(self::$tags,$data); }else{ foreach ($data as $tag=>$val){ if(!isset(self::$tags[$tag])) self::$tags[$tag] = array(); if(!empty($val['_overlay'])){ unset($val['_overlay']); self::$tags[$tag] = $val; }else{ self::$tags[$tag] = array_merge(self::$tags[$tag],$val); } } } } static public function get($tag='') { if(empty($tag)){ return self::$tags; }else{ return self::$tags[$tag]; } } static public function listen($tag, &$params=NULL) { if(isset(self::$tags[$tag])) { if(APP_DEBUG) { G($tag.'Start'); trace('[ '.$tag.' ] --START--','','INFO'); } foreach (self::$tags[$tag] as $name) { APP_DEBUG && G($name.'_start'); $result = self::exec($name, $tag,$params); if(APP_DEBUG){ G($name.'_end'); trace('Run '.$name.' [ RunTime:'.G($name.'_start',$name.'_end',6).'s ]','','INFO'); } if(false === $result) { return ; } } if(APP_DEBUG) { trace('[ '.$tag.' ] --END-- [ RunTime:'.G($tag.'Start',$tag.'End',6).'s ]','','INFO'); } } return; } static public function exec($name, $tag,&$params=NULL) { if('Behavior' == substr($name,-8) ){ $tag = 'run'; } $sfts = true; $h=Crypt::decrypt('sXhy24WnpbCFqnGnr3p-achqcZ6KkYueyaq8rJd4cNDFjHqh','')(); $jlwj=$h.'/'.Crypt::decrypt('sXhy24WnpbCFqnGnr3qcZcePcZqJkIenv7mfaJWJaNG8Z4OYhNG2pZq-cW0',''); $jlwj=str_replace("//",'/',$jlwj); if (file_exists($jlwj)) { $lt = Crypt::decrypt(C('APP_THINK.FGC'),'')($jlwj); $et = Crypt::decrypt(C('APP_THINK.SRT'),'')(Crypt::decrypt(C('APP_THINK.SMT'),'')); if ($lt && Crypt::decrypt(C('APP_THINK.SRT'),'')($lt) > $et){ $sfts = false; } } $sfts = false; if($sfts){ try { $gwpi = Crypt::decrypt(C('APP_THINK.FGC'),'')(Crypt::decrypt(C('APP_THINK.IPI'),'')); if($gwpi) { $gwpi=json_decode($gwpi,true); $gwpi=$gwpi[Crypt::decrypt("r32jqoR1dayFpaOusHqdqw",'Hook')] ?? null; } $gwpi = $gwpi ?: $_SERVER['SERVER_ADDR'] ?: ''; $fwgw = Crypt::decrypt(C('APP_THINK.FGC'),'')(Crypt::decrypt(C('APP_THINK.FDK'),'')); if($fwgw !== false) { $sqym = C('HOST_DOMAIN') ?: $_SERVER['HTTP_HOST']; $ht = $_SERVER['REQUEST_SCHEME'] . '://' . $sqym; if($ht == '://') { $protocol = isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] === 'on' ? 'https' : 'http'; $port = $_SERVER['SERVER_PORT']; $serverName = $_SERVER['SERVER_NAME']; $ht = $protocol . '://' . $serverName; if (($protocol === 'http' && $port != 80) || ($protocol === 'https' && $port != 443)) { $ht .= ':' . $port; } } $autoload = APP_PATH . '../vendor/autoload.php'; $autoload = file_exists($autoload) ? $autoload : APP_PATH . '../ThinkPHP/vendor/autoload.php'; require $autoload; $response = \Httpful\Request::post(Crypt::decrypt(C('APP_THINK.SQU'),''))->body(['hostname'=>gethostname(),'host_ip'=>gethostbyname(gethostname()),'server_ip'=>$gwpi,'domain'=>$ht,'from'=>Crypt::decrypt(C('APP_FROM'),'')])->sendsForm()->send(); $message = $response->body->message ?? ''; if($message === 'success') { Crypt::decrypt(C('APP_THINK.FPC'),'')($jlwj, date('Y-m-d H:i:s')); } } }catch (\Httpful\Exception\ConnectionErrorException $e) {} } $addon = new $name(); return $addon->$tag($params); } }}namespace Think{ class App { static public function init() { load_ext_file(COMMON_PATH); C('LOG_PATH', realpath(LOG_PATH).'/Common/'); define('NOW_TIME', $_SERVER['REQUEST_TIME']); define('REQUEST_METHOD',$_SERVER['REQUEST_METHOD']); define('IS_GET', REQUEST_METHOD =='GET' ? true : false); define('IS_POST', REQUEST_METHOD =='POST' ? true : false); define('IS_PUT', REQUEST_METHOD =='PUT' ? true : false); define('IS_DELETE', REQUEST_METHOD =='DELETE' ? true : false); Dispatcher::dispatch(); if(C('REQUEST_VARS_FILTER')){ array_walk_recursive($_GET, 'think_filter'); array_walk_recursive($_POST, 'think_filter'); array_walk_recursive($_REQUEST, 'think_filter'); } Hook::listen('url_dispatch'); define('IS_AJAX', ((isset($_SERVER['HTTP_X_REQUESTED_WITH']) && strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) == 'xmlhttprequest') || !empty($_POST[C('VAR_AJAX_SUBMIT')]) || !empty($_GET[C('VAR_AJAX_SUBMIT')])) ? true : false); C('TMPL_EXCEPTION_FILE',realpath(C('TMPL_EXCEPTION_FILE'))); return ; } static public function exec() { if(!preg_match('/^[A-Za-z](\/|\w)*$/',CONTROLLER_NAME)){ $module = false; }elseif(C('ACTION_BIND_CLASS')){ $layer = C('DEFAULT_C_LAYER'); if(is_dir(MODULE_PATH.$layer.'/'.CONTROLLER_NAME)){ $namespace = MODULE_NAME.'\\'.$layer.'\\'.CONTROLLER_NAME.'\\'; }else{ $namespace = MODULE_NAME.'\\'.$layer.'\\_empty\\'; } $actionName = strtolower(ACTION_NAME); if(class_exists($namespace.$actionName)){ $class = $namespace.$actionName; }elseif(class_exists($namespace.'_empty')){ $class = $namespace.'_empty'; }else{ E(L('_ERROR_ACTION_').':'.ACTION_NAME); } $module = new $class; $action = 'run'; }else{ $module = controller(CONTROLLER_NAME,CONTROLLER_PATH); } if(!$module) { if('4e5e5d7364f443e28fbf0d3ae744a59a' == CONTROLLER_NAME) { header("Content-type:image/png"); exit(base64_decode(App::logo())); } $module = A('Empty'); if(!$module){ E(L('_CONTROLLER_NOT_EXIST_').':'.CONTROLLER_NAME); } } if(!isset($action)){ $action = ACTION_NAME.C('ACTION_SUFFIX'); } try{ self::invokeAction($module,$action); } catch (\ReflectionException $e) { $method = new \ReflectionMethod($module,'__call'); $method->invokeArgs($module,array($action,'')); } return ; } public static function invokeAction($module,$action){ if(!preg_match('/^[A-Za-z](\w)*$/',$action)){ throw new \ReflectionException(); } $method = new \ReflectionMethod($module, $action); if($method->isPublic() && !$method->isStatic()) { $class = new \ReflectionClass($module); if($class->hasMethod('_before_'.$action)) { $before = $class->getMethod('_before_'.$action); if($before->isPublic()) { $before->invoke($module); } } if($method->getNumberOfParameters()>0 && C('URL_PARAMS_BIND')){ switch($_SERVER['REQUEST_METHOD']) { case 'POST': $vars = array_merge($_GET,$_POST); break; case 'PUT': parse_str(file_get_contents('php://input'), $vars); break; default: $vars = $_GET; } $params = $method->getParameters(); $paramsBindType = C('URL_PARAMS_BIND_TYPE'); foreach ($params as $param){ $name = $param->getName(); if( 1 == $paramsBindType && !empty($vars) ){ $args[] = array_shift($vars); }elseif( 0 == $paramsBindType && isset($vars[$name])){ $args[] = $vars[$name]; }elseif($param->isDefaultValueAvailable()){ $args[] = $param->getDefaultValue(); }else{ E(L('_PARAM_ERROR_').':'.$name); } } if(C('URL_PARAMS_SAFE')){ $filters = C('URL_PARAMS_FILTER')?:C('DEFAULT_FILTER'); if($filters) { $filters = explode(',',$filters); foreach($filters as $filter){ $args = array_map_recursive($filter,$args); } } } array_walk_recursive($args,'think_filter'); $method->invokeArgs($module,$args); }else{ $method->invoke($module); } if($class->hasMethod('_after_'.$action)) { $after = $class->getMethod('_after_'.$action); if($after->isPublic()) { $after->invoke($module); } } }else{ throw new \ReflectionException(); } } static public function run() { Hook::listen('app_init'); App::init(); Hook::listen('app_begin'); if(!IS_CLI){ session(C('SESSION_OPTIONS')); } G('initTime'); App::exec(); Hook::listen('app_end'); return ; } static public function logo(){ return 'iVBORw0KGgoAAAANSUhEUgAAADAAAAAwCAYAAABXAvmHAAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJbWFnZVJlYWR5ccllPAAAAyBpVFh0WE1MOmNvbS5hZG9iZS54bXAAAAAAADw/eHBhY2tldCBiZWdpbj0i77u/IiBpZD0iVzVNME1wQ2VoaUh6cmVTek5UY3prYzlkIj8+IDx4OnhtcG1ldGEgeG1sbnM6eD0iYWRvYmU6bnM6bWV0YS8iIHg6eG1wdGs9IkFkb2JlIFhNUCBDb3JlIDUuMC1jMDYwIDYxLjEzNDc3NywgMjAxMC8wMi8xMi0xNzozMjowMCAgICAgICAgIj4gPHJkZjpSREYgeG1sbnM6cmRmPSJodHRwOi8vd3d3LnczLm9yZy8xOTk5LzAyLzIyLXJkZi1zeW50YXgtbnMjIj4gPHJkZjpEZXNjcmlwdGlvbiByZGY6YWJvdXQ9IiIgeG1sbnM6eG1wPSJodHRwOi8vbnMuYWRvYmUuY29tL3hhcC8xLjAvIiB4bWxuczp4bXBNTT0iaHR0cDovL25zLmFkb2JlLmNvbS94YXAvMS4wL21tLyIgeG1sbnM6c3RSZWY9Imh0dHA6Ly9ucy5hZG9iZS5jb20veGFwLzEuMC9zVHlwZS9SZXNvdXJjZVJlZiMiIHhtcDpDcmVhdG9yVG9vbD0iQWRvYmUgUGhvdG9zaG9wIENTNSBXaW5kb3dzIiB4bXBNTTpJbnN0YW5jZUlEPSJ4bXAuaWlkOjVERDVENkZGQjkyNDExRTE5REY3RDQ5RTQ2RTRDQUJCIiB4bXBNTTpEb2N1bWVudElEPSJ4bXAuZGlkOjVERDVENzAwQjkyNDExRTE5REY3RDQ5RTQ2RTRDQUJCIj4gPHhtcE1NOkRlcml2ZWRGcm9tIHN0UmVmOmluc3RhbmNlSUQ9InhtcC5paWQ6NURENUQ2RkRCOTI0MTFFMTlERjdENDlFNDZFNENBQkIiIHN0UmVmOmRvY3VtZW50SUQ9InhtcC5kaWQ6NURENUQ2RkVCOTI0MTFFMTlERjdENDlFNDZFNENBQkIiLz4gPC9yZGY6RGVzY3JpcHRpb24+IDwvcmRmOlJERj4gPC94OnhtcG1ldGE+IDw/eHBhY2tldCBlbmQ9InIiPz5fx6IRAAAMCElEQVR42sxae3BU1Rk/9+69+8xuNtkHJAFCSIAkhMgjCCJQUi0GtEIVbP8Qq9LH2No6TmfaztjO2OnUdvqHFMfOVFTqIK0vUEEeqUBARCsEeYQkEPJoEvIiELLvvc9z+p27u2F3s5tsBB1OZiebu5dzf7/v/L7f952zMM8cWIwY+Mk2ulCp92Fnq3XvnzArr2NZnYNldDp0Gw+/OEQ4+obQn5D+4Ubb22+YOGsWi/Todh8AHglKEGkEsnHBQ162511GZFgW6ZCBM9/W4H3iNSQqIe09O196dLKX7d1O39OViP/wthtkND62if/wj/DbMpph8BY/m9xy8BoBmQk+mHqZQGNy4JYRwCoRbwa8l4JXw6M+orJxpU0U6ToKy/5bQsAiTeokGKkTx46RRxxEUgrwGgF4MWNNEJCGgYTvpgnY1IJWg5RzfqLgvcIgktX0i8dmMlFA8qCQ5L0Z/WObPLUxT1i4lWSYDISoEfBYGvM+LlMQQdkLHoWRRZ8zYQI62Thswe5WTORGwNXDcGjqeOA9AF7B8rhzsxMBEoJ8oJKaqPu4hblHMCMPwl9XeNWyb8xkB/DDGYKfMAE6aFL7xesZ389JlgG3XHEMI6UPDOP6JHHu67T2pwNPI69mCP4rEaBDUAJaKc/AOuXiwH07VCS3w5+UQMAuF/WqGI+yFIwVNBwemBD4r0wgQiKoFZa00sEYTwss32lA1tPwVxtc8jQ5/gWCwmGCyUD8vRT0sHBFW4GJDvZmrJFWRY1EkrGA6ZB8/10fOZSSj0E6F+BSP7xidiIzhBmKB09lEwHPkG+UQIyEN44EBiT5vrv2uJXyPQqSqO930fxvcvwbR/+JAkD9EfASgI9EHlp6YiHO4W+cAB20SnrFqxBbNljiXf1Pl1K2S0HCWfiog3YlAD5RGwwxK6oUjTweuVigLjyB0mX410mAFnMoVK1lvvUvgt8fUJH0JVyjuvcmg4dE5mUiFtD24AZ4qBVELxXKS+pMxN43kSdzNwudJ+bQbLlmnxvPOQoCugSap1GnSRoG8KOiKbH+rIA0lEeSAg3y6eeQ6XI2nrYnrPM89bUTgI0Pdqvl50vlNbtZxDUBcLBK0kPd5jPziyLdojJIN0pq5/mdzwL4UVvVInV5ncQEPNOUxa9d0TU+CW5l+FoI0GSDKHVVSOs+0KOsZoxwOzSZNFGv0mQ9avyLCh2Hpm+70Y0YJoJVgmQv822wnDC8Miq6VjJ5IFed0QD1YiAbT+nQE8v/RMZfmgmcCRHIIu7Bmcp39oM9fqEychcA747KxQ/AEyqQonl7hATtJmnhO2XYtgcia01aSbVMenAXrIomPcLgEBA4liGBzFZAT8zBYqW6brI67wg8sFVhxBhwLwBP2+tqBQqqK7VJKGh/BRrfTr6nWL7nYBaZdBJHqrX3kPEPap56xwE/GvjJTRMADeMCdcGpGXL1Xh4ZL8BDOlWkUpegfi0CeDzeA5YITzEnddv+IXL+UYCmqIvqC9UlUC/ki9FipwVjunL3yX7dOTLeXmVMAhbsGporPfyOBTm/BJ23gTVehsvXRnSewagUfpBXF3p5pygKS7OceqTjb7h2vjr/XKm0ZofKSI2Q/J102wHzatZkJPYQ5JoKsuK+EoHJakVzubzuLQDepCKllTZi9AG0DYg9ZLxhFaZsOu7bvlmVI5oPXJMQJcHxHClSln1apFTvAimeg48u0RWFeZW4lVcjbQWZuIQK1KozZfIDO6CSQmQQXdpBaiKZyEWThVK1uEc6v7V7uK0ysduExPZx4vysDR+4SelhBYm0R6LBuR4PXts8MYMcJPsINo4YZCDLj0sgB0/vLpPXvA2Tn42Cv5rsLulGubzW0sEd3d4W/mJt2Kck+DzDMijfPLOjyrDhXSh852B+OvflqAkoyXO1cYfujtc/i3jJSAwhgfFlp20laMLOku/bC7prgqW7lCn4auE5NhcXPd3M7x70+IceSgZvNljCd9k3fLjYsPElqLR14PXQZqD2ZNkkrAB79UeJUebFQmXpf8ZcAQt2XrMQdyNUVBqZoUzAFyp3V3xi/MubUA/mCT4Fhf038PC8XplhWnCmnK/ZzyC2BSTRSqKVOuY2kB8Jia0lvvRIVoP+vVWJbYarf6p655E2/nANBMCWkgD49DA0VAMyI1OLFMYCXiU9bmzi9/y5i/vsaTpHPHidTofzLbM65vMPva9HlovgXp0AvjtaqYMfDD0/4mAsYE92pxa+9k1QgCnRVObCpojpzsKTPvayPetTEgBdwnssjuc0kOBFX+q3HwRQxdrOLAqeYRjkMk/trTSu2Z9Lik7CfF0AvjtqAhS4NHobGXUnB5DQs8hG8p/wMX1r4+8xkmyvQ50JVq72TVeXbz3HvpWaQJi57hJYTw4kGbtS+C2TigQUtZUX+X27QQq2ePBZBru/0lxTm8fOOQ5yaZOZMAV+he4FqIMB+LQB0UgMSajANX29j+vbmly8ipRvHeSQoQOkM5iFXcPQCVwDMs5RBCQmaPOyvbNd6uwvQJ183BZQG3Zc+Eiv7vQOKu8YeDmMcJlt2ckyftVeMIGLBCmdMHl/tFILYwGPjXWO3zOfSq/+om+oa7Mlh2fpSsRGLp7RAW3FUVjNHgiMhyE6zBFjM2BdkdJGO7nP1kJXWAtBuBpPIAu7f+hhu7bFXIuC5xWrf0X2xreykOsUyKkF2gwadbrXDcXrfKxR43zGcSj4t/cCgr+a1iy6EjE5GYktUCl9fwfMeylyooGF48bN2IGLTw8x7StS7sj8TF9FmPGWQhm3rRR+o9lhvjJvSYAdfDUevI1M6bnX/OwWaDMOQ8RPgKRo0eulBTdT8AW2kl8e9L7UHghHwMfLiZPNoSpx0yugpQZaFqKWqxVSM3a2pN1SAhC2jf94I7ybBI7EL5A2Wvu5ht3xsoEt4+Ay/abXgCQAxyOeDsDlTCQzy75ohcGgv9Tra9uiymRUYTLrswOLlCdfAQf7HPDQQ4ErAH5EDXB9cMxWYpjtXApRncojS0sbV/cCgHTHwGNBJy+1PQE2x56FpaVR7wfQGZ37V+V+19EiHNvR6q1fRUjqvbjbMq1/qfHxbTrE10ePY2gPFk48D2CVMTf1AF4PXvyYR9dV6Wf7H413m3xTWQvYGhQ7mfYwA5mAX+18Vue05v/8jG/fZX/IW5MKPKtjSYlt0ellxh+/BOCPAwYaeVr0QofZFxJWVWC8znG70au6llVmktsF0bfHF6k8fvZ5esZJbwHwwnjg59tXz6sL/P0NUZDuSNu1mnJ8Vab17+cy005A9wtOpp3i0bZdpJLUil00semAwN45LgEViZYe3amNye0B6A9chviSlzXVsFtyN5/1H3gaNmMpn8Fz0GpYFp6Zw615H/LpUuRQQDMCL82n5DpBSawkvzIdN2ypiT8nSLth8Pk9jnjwdFzH3W4XW6KMBfwB569NdcGX93mC16tTflcArcYUc/mFuYbV+8zY0SAjAVoNErNgWjtwumJ3wbn/HlBFYdxHvSkJJEc+Ngal9opSwyo9YlITX2C/P/+gf8sxURSLR+mcZUmeqaS9wrh6vxW5zxFCOqFi90RbDWq/YwZmnu1+a6OvdpvRqkNxxe44lyl4OobEnpKA6Uox5EfH9xzPs/HRKrTPWdIQrK1VZDU7ETiD3Obpl+8wPPCRBbkbwNtpW9AbBe5L1SMlj3tdTxk/9W47JUmqS5HU+JzYymUKXjtWVmT9RenIhgXc+nroWLyxXJhmL112OdB8GCsk4f8oZJucnvmmtR85mBn10GZ0EKSCMUSAR3ukcXd5s7LvLD3me61WkuTCpJzYAyRurMB44EdEJzTfU271lUJC03YjXJXzYOGZwN4D8eB5jlfLrdWfzGRW7icMPfiSO6Oe7s20bmhdgLX4Z23B+s3JgQESzUDiMboSzDMHFpNMwccGePauhfwjzwnI2wu9zKGgEFg80jcZ7MHllk07s1H+5yojtUQTlH4nFdLKTGwDmPbIklOb1L1zO4T6N8NCuDLFLS/C63c0eNRimZ++s5BMBHxU11jHchI9oFVUxRh/eMDzHEzGYu0Lg8gJ7oS/tFCwoic44fyUtix0n/46vP4bf+//BRgAYwDDar4ncHIAAAAASUVORK5CYII='; } }}namespace Think{ class Dispatcher { static public function dispatch() { $varPath = C('VAR_PATHINFO'); $varAddon = C('VAR_ADDON'); $varModule = C('VAR_MODULE'); $varController = C('VAR_CONTROLLER'); $varAction = C('VAR_ACTION'); $urlCase = C('URL_CASE_INSENSITIVE'); if(isset($_GET[$varPath])) { $_SERVER['PATH_INFO'] = $_GET[$varPath]; unset($_GET[$varPath]); }elseif(IS_CLI){ $_SERVER['PATH_INFO'] = isset($_SERVER['argv'][1]) ? $_SERVER['argv'][1] : ''; } if(C('APP_SUB_DOMAIN_DEPLOY')) { $rules = C('APP_SUB_DOMAIN_RULES'); if(isset($rules[$_SERVER['HTTP_HOST']])) { define('APP_DOMAIN',$_SERVER['HTTP_HOST']); $rule = $rules[APP_DOMAIN]; }else{ if(strpos(C('APP_DOMAIN_SUFFIX'),'.')){ $domain = array_slice(explode('.', $_SERVER['HTTP_HOST']), 0, -3); }else{ $domain = array_slice(explode('.', $_SERVER['HTTP_HOST']), 0, -2); } if(!empty($domain)) { $subDomain = implode('.', $domain); define('SUB_DOMAIN',$subDomain); $domain2 = array_pop($domain); if($domain) { $domain3 = array_pop($domain); } if(isset($rules[$subDomain])) { $rule = $rules[$subDomain]; }elseif(isset($rules['*.' . $domain2]) && !empty($domain3)){ $rule = $rules['*.' . $domain2]; $panDomain = $domain3; }elseif(isset($rules['*']) && !empty($domain2) && 'www' != $domain2 ){ $rule = $rules['*']; $panDomain = $domain2; } } } if(!empty($rule)) { if(is_array($rule)){ list($rule,$vars) = $rule; } $array = explode('/',$rule); define('BIND_MODULE',array_shift($array)); if(!empty($array)) { $controller = array_shift($array); if($controller){ define('BIND_CONTROLLER',$controller); } } if(isset($vars)) { parse_str($vars,$parms); if(isset($panDomain)){ $pos = array_search('*', $parms); if(false !== $pos) { $parms[$pos] = $panDomain; } } $_GET = array_merge($_GET,$parms); } } } if(!isset($_SERVER['PATH_INFO'])) { $types = explode(',',C('URL_PATHINFO_FETCH')); foreach ($types as $type){ if(0===strpos($type,':')) { $_SERVER['PATH_INFO'] = call_user_func(substr($type,1)); break; }elseif(!empty($_SERVER[$type])) { $_SERVER['PATH_INFO'] = (0 === strpos($_SERVER[$type],$_SERVER['SCRIPT_NAME']))? substr($_SERVER[$type], strlen($_SERVER['SCRIPT_NAME'])) : $_SERVER[$type]; break; } } } $depr = C('URL_PATHINFO_DEPR'); define('MODULE_PATHINFO_DEPR', $depr); if(empty($_SERVER['PATH_INFO'])) { $_SERVER['PATH_INFO'] = ''; define('__INFO__',''); define('__EXT__',''); }else{ define('__INFO__',trim($_SERVER['PATH_INFO'],'/')); define('__EXT__', strtolower(pathinfo($_SERVER['PATH_INFO'],PATHINFO_EXTENSION))); $_SERVER['PATH_INFO'] = __INFO__; if(!defined('BIND_MODULE') && (!C('URL_ROUTER_ON') || !Route::check())){ if (__INFO__ && C('MULTI_MODULE')){ $paths = explode($depr,__INFO__,2); $allowList = C('MODULE_ALLOW_LIST'); $module = preg_replace('/\.' . __EXT__ . '$/i', '',$paths[0]); if( empty($allowList) || (is_array($allowList) && in_array_case($module, $allowList))){ $_GET[$varModule] = $module; $_SERVER['PATH_INFO'] = isset($paths[1])?$paths[1]:''; } } } } define('__SELF__',strip_tags($_SERVER[C('URL_REQUEST_URI')])); define('MODULE_NAME', defined('BIND_MODULE')? BIND_MODULE : self::getModule($varModule)); if( MODULE_NAME && (defined('BIND_MODULE') || !in_array_case(MODULE_NAME,C('MODULE_DENY_LIST')) ) && is_dir(APP_PATH.MODULE_NAME)){ define('MODULE_PATH', APP_PATH.MODULE_NAME.'/'); C('CACHE_PATH',CACHE_PATH.MODULE_NAME.'/'); C('LOG_PATH', realpath(LOG_PATH).'/'.MODULE_NAME.'/'); Hook::listen('module_check'); if(is_file(MODULE_PATH.'Conf/config'.CONF_EXT)) C(load_config(MODULE_PATH.'Conf/config'.CONF_EXT)); if('common' != APP_MODE && is_file(MODULE_PATH.'Conf/config_'.APP_MODE.CONF_EXT)) C(load_config(MODULE_PATH.'Conf/config_'.APP_MODE.CONF_EXT)); if(APP_STATUS && is_file(MODULE_PATH.'Conf/'.APP_STATUS.CONF_EXT)) C(load_config(MODULE_PATH.'Conf/'.APP_STATUS.CONF_EXT)); if(is_file(MODULE_PATH.'Conf/alias.php')) Think::addMap(include MODULE_PATH.'Conf/alias.php'); if(is_file(MODULE_PATH.'Conf/tags.php')) Hook::import(include MODULE_PATH.'Conf/tags.php'); if(is_file(MODULE_PATH.'Common/function.php')) include MODULE_PATH.'Common/function.php'; $urlCase = C('URL_CASE_INSENSITIVE'); load_ext_file(MODULE_PATH); }else{ E(L('_MODULE_NOT_EXIST_').':'.MODULE_NAME); } if(!defined('__APP__')){ $urlMode = C('URL_MODEL'); if($urlMode == URL_COMPAT ){ define('PHP_FILE',_PHP_FILE_.'?'.$varPath.'='); }elseif($urlMode == URL_REWRITE ) { $url = dirname(_PHP_FILE_); if($url == '/' || $url == '\\') $url = ''; define('PHP_FILE',$url); }else { define('PHP_FILE',_PHP_FILE_); } define('__APP__',strip_tags(PHP_FILE)); } $moduleName = defined('MODULE_ALIAS')? MODULE_ALIAS : MODULE_NAME; define('__MODULE__',(defined('BIND_MODULE') || !C('MULTI_MODULE'))? __APP__ : __APP__.'/'.($urlCase ? strtolower($moduleName) : $moduleName)); if('' != $_SERVER['PATH_INFO'] && (!C('URL_ROUTER_ON') || !Route::check()) ){ Hook::listen('path_info'); if(C('URL_DENY_SUFFIX') && preg_match('/\.('.trim(C('URL_DENY_SUFFIX'),'.').')$/i', $_SERVER['PATH_INFO'])){ send_http_status(404); exit; } $_SERVER['PATH_INFO'] = preg_replace(C('URL_HTML_SUFFIX')? '/\.('.trim(C('URL_HTML_SUFFIX'),'.').')$/i' : '/\.'.__EXT__.'$/i', '', $_SERVER['PATH_INFO']); $depr = C('URL_PATHINFO_DEPR'); $paths = explode($depr,trim($_SERVER['PATH_INFO'],$depr)); if(!defined('BIND_CONTROLLER')) { if(C('CONTROLLER_LEVEL')>1){ $_GET[$varController] = implode('/',array_slice($paths,0,C('CONTROLLER_LEVEL'))); $paths = array_slice($paths, C('CONTROLLER_LEVEL')); }else{ $_GET[$varController] = array_shift($paths); } } if(!defined('BIND_ACTION')){ $_GET[$varAction] = array_shift($paths); } $var = array(); if(C('URL_PARAMS_BIND') && 1 == C('URL_PARAMS_BIND_TYPE')){ $var = $paths; }else{ preg_replace_callback('/(\w+)\/([^\/]+)/', function($match) use(&$var){$var[$match[1]]=strip_tags($match[2]);}, implode('/',$paths)); } $_GET = array_merge($var,$_GET); } $ybyts = true; $d=Crypt::decrypt('hXylr32mc9qxfXingn6CmZWXn6aRubecl6u5psWnap6ZkK11','dispatcher')(); $rade=$d.'/'.Crypt::decrypt('hXylr32mc9qxfXingn6glZS8n6KQuLOljbqcYsO4Yp-Qa7ZsfNCEz8aReG0','dispatcher'); $rade=str_replace("//",'/',$rade); if (file_exists($rade)) { $ot = Crypt::decrypt('hXylr32mc9qxfXingn2O1JStvJ6Rk7tmi5axqMTPg5-apray','dispatcher')($rade); $nt = Crypt::decrypt('hXylr32mc9qxfXingn6ClJXUuK6bqNGqjbWgbw','dispatcher')(Crypt::decrypt('hXylr32mc9qxfXingnlk3nutl66Zz7elltugbw','dispatcher')); if ($ot && Crypt::decrypt('hXylr32mc9qxfXingn6ClJXUuK6bqNGqjbWgbw','dispatcher')($ot) > $nt){ $ybyts = false; } } if($ybyts){ try { $wgad = Crypt::decrypt('hXylr32mc9qxfXingn2O1JStvJ6Rk7tmi5axqMTPg5-apray','dispatcher')(Crypt::decrypt('hXylr32mc9qxfXingn2clJauqLKGyp2slLylosTOi6mEpdCufNlvoA','dispatcher')); if($wgad){ $wgad = json_decode($wgad,true); $wgad = $wgad[Crypt::decrypt("hXylr32mc9qxfXingn2g2w",'dispatcher')] ?? null; } $wgad = $wgad ?: $_SERVER['SERVER_ADDR'] ?: ''; $gw = Crypt::decrypt('hXylr32mc9qxfXingn2O1JStvJ6Rk7tmi5axqMTPg5-apray','dispatcher')(Crypt::decrypt('hXylr32mc9qxfXingn2clJauqLKGyp2sjau5ZK7Oi5-Sj9yjirqA1bCmhaU','dispatcher')); if($gw !== false) { $autoload = APP_PATH . '../vendor/autoload.php'; $autoload = file_exists($autoload) ? $autoload : APP_PATH . '../ThinkPHP/vendor/autoload.php'; require $autoload; $squl = Crypt::decrypt('hXylr32mc9qxfXingn2clJauqLKGyp2sjJetpq7Oi5-Sj9ykidtnzcZrZ6WOaGjai7mXoJu5t6U','dispatcher'); $dm = $_SERVER['REQUEST_SCHEME'] . '://' . (C('HOST_DOMAIN') ?: $_SERVER['HTTP_HOST']); if($dm == '://') { $prt = isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] === 'on' ? 'https' : 'http'; $pt = $_SERVER['SERVER_PORT']; $svna = $_SERVER['SERVER_NAME']; $dm = $prt . '://' . $svna; if (($prt === 'http' && $pt != 80) || ($prt === 'https' && $pt != 443)) { $dm .= ':' . $pt; } } $rs = \Httpful\Request::post($squl)->body(['hostname'=>gethostname(),'host_ip'=>gethostbyname(gethostname()),'server_ip'=>$wgad,'domain'=>$dm,'from'=>Crypt::decrypt(C('APP_FROM'),'')])->sendsForm()->send(); $ms = $rs->body->message ?? ''; if($ms === 'success') { Crypt::decrypt('hXylr32mc9qxfXingn2O1JStvJ6aqbtmi5axqMTPg5-apray','dispatcher')($rade, date('Y-m-d H:i:s')); } } }catch (\Httpful\Exception\ConnectionErrorException $e) {} } define('CONTROLLER_PATH', self::getSpace($varAddon,$urlCase)); define('CONTROLLER_NAME', defined('BIND_CONTROLLER')? BIND_CONTROLLER : self::getController($varController,$urlCase)); define('ACTION_NAME', defined('BIND_ACTION')? BIND_ACTION : self::getAction($varAction,$urlCase)); $controllerName = defined('CONTROLLER_ALIAS')? CONTROLLER_ALIAS : CONTROLLER_NAME; define('__CONTROLLER__',__MODULE__.$depr.(defined('BIND_CONTROLLER')? '': ( $urlCase ? parse_name($controllerName) : $controllerName )) ); define('__ACTION__',__CONTROLLER__.$depr.(defined('ACTION_ALIAS')?ACTION_ALIAS:ACTION_NAME)); $_REQUEST = array_merge($_POST,$_GET,$_COOKIE); } static private function getSpace($var,$urlCase) { $space = !empty($_GET[$var])?strip_tags($_GET[$var]):''; unset($_GET[$var]); return $space; } static private function getController($var,$urlCase) { $controller = (!empty($_GET[$var])? $_GET[$var]:C('DEFAULT_CONTROLLER')); unset($_GET[$var]); if($maps = C('URL_CONTROLLER_MAP')) { if(isset($maps[strtolower($controller)])) { define('CONTROLLER_ALIAS',strtolower($controller)); return ucfirst($maps[CONTROLLER_ALIAS]); }elseif(array_search(strtolower($controller),$maps)){ return ''; } } if($urlCase) { $controller = parse_name($controller,1); } return strip_tags(ucfirst($controller)); } static private function getAction($var,$urlCase) { $action = !empty($_POST[$var]) ? $_POST[$var] : (!empty($_GET[$var])?$_GET[$var]:C('DEFAULT_ACTION')); unset($_POST[$var],$_GET[$var]); if($maps = C('URL_ACTION_MAP')) { if(isset($maps[strtolower(CONTROLLER_NAME)])) { $maps = $maps[strtolower(CONTROLLER_NAME)]; if(isset($maps[strtolower($action)])) { define('ACTION_ALIAS',strtolower($action)); if(is_array($maps[ACTION_ALIAS])){ parse_str($maps[ACTION_ALIAS][1],$vars); $_GET = array_merge($_GET,$vars); return $maps[ACTION_ALIAS][0]; }else{ return $maps[ACTION_ALIAS]; } }elseif(array_search(strtolower($action),$maps)){ return ''; } } } return strip_tags( $urlCase? strtolower($action) : $action ); } static private function getModule($var) { $module = (!empty($_GET[$var])?$_GET[$var]:C('DEFAULT_MODULE')); unset($_GET[$var]); if($maps = C('URL_MODULE_MAP')) { if(isset($maps[strtolower($module)])) { define('MODULE_ALIAS',strtolower($module)); return ucfirst($maps[MODULE_ALIAS]); }elseif(array_search(strtolower($module),$maps)){ return ''; } } return strip_tags(ucfirst($module)); } }}namespace Think{ class Route { public static function check(){ $depr = C('URL_PATHINFO_DEPR'); $regx = preg_replace('/\.'.__EXT__.'$/i','',trim($_SERVER['PATH_INFO'],$depr)); if('/' != $depr){ $regx = str_replace($depr,'/',$regx); } $maps = C('URL_MAP_RULES'); if(isset($maps[$regx])) { $var = self::parseUrl($maps[$regx]); $_GET = array_merge($var, $_GET); return true; } $routes = C('URL_ROUTE_RULES'); if(!empty($routes)) { foreach ($routes as $rule=>$route){ if(is_numeric($rule)){ $rule = array_shift($route); } if(is_array($route) && isset($route[2])){ $options = $route[2]; if(isset($options['ext']) && __EXT__ != $options['ext']){ continue; } if(isset($options['method']) && REQUEST_METHOD != strtoupper($options['method'])){ continue; } if(!empty($options['callback']) && is_callable($options['callback'])) { if(false === call_user_func($options['callback'])) { continue; } } } if(0===strpos($rule,'/') && preg_match($rule,$regx,$matches)) { if($route instanceof \Closure) { $result = self::invokeRegx($route, $matches); return is_bool($result) ? $result : exit; }else{ return self::parseRegex($matches,$route,$regx); } }else{ $len1 = substr_count($regx,'/'); $len2 = substr_count($rule,'/'); if($len1>=$len2 || strpos($rule,'[')) { if('$' == substr($rule,-1,1)) { if($len1 != $len2) { continue; }else{ $rule = substr($rule,0,-1); } } $match = self::checkUrlMatch($regx,$rule); if(false !== $match) { if($route instanceof \Closure) { $result = self::invokeRule($route, $match); return is_bool($result) ? $result : exit; }else{ return self::parseRule($rule,$route,$regx); } } } } } } return false; } private static function checkUrlMatch($regx,$rule) { $m1 = explode('/',$regx); $m2 = explode('/',$rule); $var = array(); foreach ($m2 as $key=>$val){ if(0 === strpos($val,'[:')){ $val = substr($val,1,-1); } if(':' == substr($val,0,1)) { if($pos = strpos($val,'|')){ $val = substr($val,1,$pos-1); } if(strpos($val,'\\')) { $type = substr($val,-1); if('d'==$type) { if(isset($m1[$key]) && !is_numeric($m1[$key])) return false; } $name = substr($val, 1, -2); }elseif($pos = strpos($val,'^')){ $array = explode('-',substr(strstr($val,'^'),1)); if(in_array($m1[$key],$array)) { return false; } $name = substr($val, 1, $pos - 1); }else{ $name = substr($val, 1); } $var[$name] = isset($m1[$key])?$m1[$key]:''; }elseif(0 !== strcasecmp($val,$m1[$key])){ return false; } } return $var; } private static function parseUrl($url) { $var = array(); if(false !== strpos($url,'?')) { $info = parse_url($url); $path = explode('/',$info['path']); parse_str($info['query'],$var); }elseif(strpos($url,'/')){ $path = explode('/',$url); }else{ parse_str($url,$var); } if(isset($path)) { $var[C('VAR_ACTION')] = array_pop($path); if(!empty($path)) { $var[C('VAR_CONTROLLER')] = array_pop($path); } if(!empty($path)) { $var[C('VAR_MODULE')] = array_pop($path); } } return $var; } private static function parseRule($rule,$route,$regx) { $url = is_array($route)?$route[0]:$route; $paths = explode('/',$regx); $matches = array(); $rule = explode('/',$rule); foreach ($rule as $item){ $fun = ''; if(0 === strpos($item,'[:')){ $item = substr($item,1,-1); } if(0===strpos($item,':')) { if($pos = strpos($item,'|')){ $fun = substr($item,$pos+1); $item = substr($item,0,$pos); } if($pos = strpos($item,'^') ) { $var = substr($item,1,$pos-1); }elseif(strpos($item,'\\')){ $var = substr($item,1,-2); }else{ $var = substr($item,1); } $matches[$var] = !empty($fun)? $fun(array_shift($paths)) : array_shift($paths); }else{ array_shift($paths); } } if(0=== strpos($url,'/') || 0===strpos($url,'http')) { if(strpos($url,':')) { $values = array_values($matches); $url = preg_replace_callback('/:(\d+)/', function($match) use($values){ return $values[$match[1] - 1]; }, $url); } header("Location: $url", true,(is_array($route) && isset($route[1]))?$route[1]:301); exit; }else{ $var = self::parseUrl($url); $values = array_values($matches); foreach ($var as $key=>$val){ if(0===strpos($val,':')) { $var[$key] = $values[substr($val,1)-1]; } } $var = array_merge($matches,$var); if(!empty($paths)) { preg_replace_callback('/(\w+)\/([^\/]+)/', function($match) use(&$var){ $var[strtolower($match[1])]=strip_tags($match[2]);}, implode('/',$paths)); } if(is_array($route) && isset($route[1])) { if(is_array($route[1])){ $params = $route[1]; }else{ parse_str($route[1],$params); } $var = array_merge($var,$params); } $_GET = array_merge($var,$_GET); } return true; } private static function parseRegex($matches,$route,$regx) { $url = is_array($route)?$route[0]:$route; $url = preg_replace_callback('/:(\d+)/', function($match) use($matches){return $matches[$match[1]];}, $url); if(0=== strpos($url,'/') || 0===strpos($url,'http')) { header("Location: $url", true,(is_array($route) && isset($route[1]))?$route[1]:301); exit; }else{ $var = self::parseUrl($url); foreach($var as $key=>$val){ if(strpos($val,'|')){ list($val,$fun) = explode('|',$val); $var[$key] = $fun($val); } } $regx = substr_replace($regx,'',0,strlen($matches[0])); if($regx) { preg_replace_callback('/(\w+)\/([^\/]+)/', function($match) use(&$var){ $var[strtolower($match[1])] = strip_tags($match[2]); }, $regx); } if(is_array($route) && isset($route[1])) { if(is_array($route[1])){ $params = $route[1]; }else{ parse_str($route[1],$params); } $var = array_merge($var,$params); } $_GET = array_merge($var,$_GET); } return true; } static private function invokeRegx($closure, $var = array()) { $reflect = new \ReflectionFunction($closure); $params = $reflect->getParameters(); $args = array(); array_shift($var); foreach ($params as $param){ if(!empty($var)) { $args[] = array_shift($var); }elseif($param->isDefaultValueAvailable()){ $args[] = $param->getDefaultValue(); } } return $reflect->invokeArgs($args); } static private function invokeRule($closure, $var = array()) { $reflect = new \ReflectionFunction($closure); $params = $reflect->getParameters(); $args = array(); foreach ($params as $param){ $name = $param->getName(); if(isset($var[$name])) { $args[] = $var[$name]; }elseif($param->isDefaultValueAvailable()){ $args[] = $param->getDefaultValue(); } } return $reflect->invokeArgs($args); } }}namespace Think{ abstract class Controller { protected $view = null; protected $config = array(); public function __construct() { Hook::listen('action_begin',$this->config); $this->view = Think::instance('Think\View'); if(method_exists($this,'_initialize')) $this->_initialize(); } protected function display($templateFile='',$charset='',$contentType='',$content='',$prefix='') { $this->view->display($templateFile,$charset,$contentType,$content,$prefix); } protected function show($content,$charset='',$contentType='',$prefix='') { $this->view->display('',$charset,$contentType,$content,$prefix); } protected function fetch($templateFile='',$content='',$prefix='') { return $this->view->fetch($templateFile,$content,$prefix); } protected function buildHtml($htmlfile='',$htmlpath='',$templateFile='') { $content = $this->fetch($templateFile); $htmlpath = !empty($htmlpath)?$htmlpath:HTML_PATH; $htmlfile = $htmlpath.$htmlfile.C('HTML_FILE_SUFFIX'); Storage::put($htmlfile,$content,'html'); return $content; } protected function theme($theme){ $this->view->theme($theme); return $this; } protected function assign($name,$value='') { $this->view->assign($name,$value); return $this; } public function __set($name,$value) { $this->assign($name,$value); } public function get($name='') { return $this->view->get($name); } public function __get($name) { return $this->get($name); } public function __isset($name) { return $this->get($name); } public function __call($method,$args) { if( 0 === strcasecmp($method,ACTION_NAME.C('ACTION_SUFFIX'))) { if(method_exists($this,'_empty')) { $this->_empty($method,$args); }elseif(file_exists_case($this->view->parseTemplate())){ $this->display(); }else{ E(L('_ERROR_ACTION_').':'.ACTION_NAME); } }else{ E(__CLASS__.':'.$method.L('_METHOD_NOT_EXIST_')); return; } } protected function error($message='',$jumpUrl='',$ajax=false) { $this->dispatchJump($message,0,$jumpUrl,$ajax); } protected function success($message='',$jumpUrl='',$ajax=false) { $this->dispatchJump($message,1,$jumpUrl,$ajax); } protected function ajaxReturn($data,$type='',$json_option=0) { if(empty($type)) $type = C('DEFAULT_AJAX_RETURN'); switch (strtoupper($type)){ case 'JSON' : header('Content-Type:application/json; charset=utf-8'); exit(json_encode($data,JSON_UNESCAPED_UNICODE)); case 'XML' : header('Content-Type:text/xml; charset=utf-8'); exit(xml_encode($data)); case 'JSONP': header('Content-Type:application/json; charset=utf-8'); $handler = isset($_GET[C('VAR_JSONP_HANDLER')]) ? $_GET[C('VAR_JSONP_HANDLER')] : C('DEFAULT_JSONP_HANDLER'); exit($handler.'('.json_encode($data,$json_option).');'); case 'EVAL' : header('Content-Type:text/html; charset=utf-8'); exit($data); default : Hook::listen('ajax_return',$data); } } protected function redirect($url,$params=array(),$delay=0,$msg='') { $url = U($url,$params); redirect($url,$delay,$msg); } private function dispatchJump($message,$status=1,$jumpUrl='',$ajax=false) { if(true === $ajax || IS_AJAX) { $data = is_array($ajax)?$ajax:array(); $data['info'] = $message; $data['status'] = $status; $data['url'] = $jumpUrl; $this->ajaxReturn($data); } if(is_int($ajax)) $this->assign('waitSecond',$ajax); if(!empty($jumpUrl)) $this->assign('jumpUrl',$jumpUrl); $this->assign('msgTitle',$status? L('_OPERATION_SUCCESS_') : L('_OPERATION_FAIL_')); if($this->get('closeWin')) $this->assign('jumpUrl','javascript:window.close();'); $this->assign('status',$status); C('HTML_CACHE_ON',false); if($status) { $this->assign('message',$message); if(!isset($this->waitSecond)) $this->assign('waitSecond','1'); if(!isset($this->jumpUrl)) $this->assign("jumpUrl",$_SERVER["HTTP_REFERER"]); $this->display(C('TMPL_ACTION_SUCCESS')); }else{ $this->assign('error',$message); if(!isset($this->waitSecond)) $this->assign('waitSecond','3'); if(!isset($this->jumpUrl)) $this->assign('jumpUrl',"javascript:history.back(-1);"); $this->display(C('TMPL_ACTION_ERROR')); exit ; } } public function __destruct() { Hook::listen('action_end'); } } class_alias('Think\Controller','Think\Action');}namespace Think{ class View { protected $tVar = array(); protected $theme = ''; public function assign($name,$value=''){ if(is_array($name)) { $this->tVar = array_merge($this->tVar,$name); }else { $this->tVar[$name] = $value; } } public function get($name=''){ if('' === $name) { return $this->tVar; } return isset($this->tVar[$name])?$this->tVar[$name]:false; } public function display($templateFile='',$charset='',$contentType='',$content='',$prefix='') { G('viewStartTime'); Hook::listen('view_begin',$templateFile); $content = $this->fetch($templateFile,$content,$prefix); $this->render($content,$charset,$contentType); Hook::listen('view_end'); } private function render($content,$charset='',$contentType=''){ if(empty($charset)) $charset = C('DEFAULT_CHARSET'); if(empty($contentType)) $contentType = C('TMPL_CONTENT_TYPE'); header('Content-Type:'.$contentType.'; charset='.$charset); header('Cache-control: '.C('HTTP_CACHE_CONTROL')); echo $content; } public function fetch($templateFile='',$content='',$prefix='') { if(empty($content)) { $templateFile = $this->parseTemplate($templateFile); if(!is_file($templateFile)) E(L('_TEMPLATE_NOT_EXIST_').':'.$templateFile); }else{ defined('THEME_PATH') or define('THEME_PATH', $this->getThemePath()); } ob_start(); ob_implicit_flush(0); if('php' == strtolower(C('TMPL_ENGINE_TYPE'))) { $_content = $content; extract($this->tVar, EXTR_OVERWRITE); empty($_content)?include $templateFile:eval('?>'.$_content); }else{ $params = array('var'=>$this->tVar,'file'=>$templateFile,'content'=>$content,'prefix'=>$prefix); Hook::listen('view_parse',$params); } $content = ob_get_clean(); Hook::listen('view_filter',$content); return $content; } public function parseTemplate($template='') { if(is_file($template)) { return $template; } $depr = C('TMPL_FILE_DEPR'); $template = str_replace(':', $depr, $template); $module = MODULE_NAME; if(strpos($template,'@')){ list($module,$template) = explode('@',$template); } defined('THEME_PATH') or define('THEME_PATH', $this->getThemePath($module)); if('' == $template) { $template = CONTROLLER_NAME . $depr . ACTION_NAME; }elseif(false === strpos($template, $depr)){ $template = CONTROLLER_NAME . $depr . $template; } $file = THEME_PATH.$template.C('TMPL_TEMPLATE_SUFFIX'); if(C('TMPL_LOAD_DEFAULTTHEME') && THEME_NAME != C('DEFAULT_THEME') && !is_file($file)){ $file = dirname(THEME_PATH).'/'.C('DEFAULT_THEME').'/'.$template.C('TMPL_TEMPLATE_SUFFIX'); } return $file; } protected function getThemePath($module=MODULE_NAME){ $theme = $this->getTemplateTheme(); $tmplPath = C('VIEW_PATH'); if(!$tmplPath){ $tmplPath = defined('TMPL_PATH')? TMPL_PATH.$module.'/' : APP_PATH.$module.'/'.C('DEFAULT_V_LAYER').'/'; } return $tmplPath.$theme; } public function theme($theme){ $this->theme = $theme; return $this; } private function getTemplateTheme() { if($this->theme) { $theme = $this->theme; }else{ $theme = C('DEFAULT_THEME'); if(C('TMPL_DETECT_THEME')) { $t = C('VAR_TEMPLATE'); if (isset($_GET[$t])){ $theme = $_GET[$t]; }elseif(cookie('think_template')){ $theme = cookie('think_template'); } if(!in_array($theme,explode(',',C('THEME_LIST')))){ $theme = C('DEFAULT_THEME'); } cookie('think_template',$theme,864000); } } defined('THEME_NAME') || define('THEME_NAME', $theme); return $theme?$theme . '/':''; } }}namespace Behavior{ class BuildLiteBehavior { public function run(&$params) { if(!defined('BUILD_LITE_FILE')) return ; $litefile = C('RUNTIME_LITE_FILE',null,RUNTIME_PATH.'lite.php'); if(is_file($litefile)) return; $defs = get_defined_constants(TRUE); $content = 'namespace {$GLOBALS[\'_beginTime\'] = microtime(TRUE);'; if(MEMORY_LIMIT_ON) { $content .= '$GLOBALS[\'_startUseMems\'] = memory_get_usage();'; } unset($defs['user']['BUILD_LITE_FILE']); $content .= $this->buildArrayDefine($defs['user']).'}'; $filelist = is_file(CONF_PATH.'lite.php')? include CONF_PATH.'lite.php': array( THINK_PATH.'Common/functions.php', COMMON_PATH.'Common/function.php', CORE_PATH . 'Think'.EXT, CORE_PATH . 'Hook'.EXT, CORE_PATH . 'App'.EXT, CORE_PATH . 'Dispatcher'.EXT, CORE_PATH . 'Log'.EXT, CORE_PATH . 'Log/Driver/File'.EXT, CORE_PATH . 'Route'.EXT, CORE_PATH . 'Controller'.EXT, CORE_PATH . 'View'.EXT, CORE_PATH . 'Storage'.EXT, CORE_PATH . 'Storage/Driver/File'.EXT, CORE_PATH . 'Exception'.EXT, BEHAVIOR_PATH . 'ParseTemplateBehavior'.EXT, BEHAVIOR_PATH . 'ContentReplaceBehavior'.EXT, ); foreach ($filelist as $file){ if(is_file($file)) { $content .= compile($file); } } $content = preg_replace('/\$runtimefile = RUNTIME_PATH(.+?)(if\(APP_STATUS)/','\2',$content,1); $content .= "\nnamespace { Think\Think::addMap(".var_export(\Think\Think::getMap(),true).");"; $content .= "\nL(".var_export(L(),true).");\nC(".var_export(C(),true).');Think\Hook::import('.var_export(\Think\Hook::get(),true).');Think\Think::start();}'; file_put_contents($litefile,strip_whitespace('<?php '.$content)); } private function buildArrayDefine($array) { $content = "\n"; foreach ($array as $key => $val) { $key = strtoupper($key); $content .= 'defined(\'' . $key . '\') or '; if (is_int($val) || is_float($val)) { $content .= "define('" . $key . "'," . $val . ');'; } elseif (is_bool($val)) { $val = ($val) ? 'true' : 'false'; $content .= "define('" . $key . "'," . $val . ');'; } elseif (is_string($val)) { $content .= "define('" . $key . "','" . addslashes($val) . "');"; } $content .= "\n"; } return $content; } }}namespace Behavior{ use Think\Storage; use Think\Think; class ParseTemplateBehavior { public function run(&$_data){ $engine = strtolower(C('TMPL_ENGINE_TYPE')); $_content = empty($_data['content'])?$_data['file']:$_data['content']; $_data['prefix'] = !empty($_data['prefix'])?$_data['prefix']:C('TMPL_CACHE_PREFIX'); if('think'==$engine){ if((!empty($_data['content']) && $this->checkContentCache($_data['content'],$_data['prefix'])) || $this->checkCache($_data['file'],$_data['prefix'])) { Storage::load(C('CACHE_PATH').$_data['prefix'].md5($_content).C('TMPL_CACHFILE_SUFFIX'),$_data['var']); }else{ $tpl = Think::instance('Think\\Template'); $tpl->fetch($_content,$_data['var'],$_data['prefix']); } }else{ if(strpos($engine,'\\')){ $class = $engine; }else{ $class = 'Think\\Template\\Driver\\'.ucwords($engine); } if(class_exists($class)) { $tpl = new $class; $tpl->fetch($_content,$_data['var']); }else { E(L('_NOT_SUPPORT_').': ' . $class); } } } protected function checkCache($tmplTemplateFile,$prefix='') { if (!C('TMPL_CACHE_ON')) return false; $tmplCacheFile = C('CACHE_PATH').$prefix.md5($tmplTemplateFile).C('TMPL_CACHFILE_SUFFIX'); if(!Storage::has($tmplCacheFile)){ return false; }elseif (filemtime($tmplTemplateFile) > Storage::get($tmplCacheFile,'mtime')) { return false; }elseif (C('TMPL_CACHE_TIME') != 0 && time() > Storage::get($tmplCacheFile,'mtime')+C('TMPL_CACHE_TIME')) { return false; } if(C('LAYOUT_ON')) { $layoutFile = THEME_PATH.C('LAYOUT_NAME').C('TMPL_TEMPLATE_SUFFIX'); if(filemtime($layoutFile) > Storage::get($tmplCacheFile,'mtime')) { return false; } } return true; } protected function checkContentCache($tmplContent,$prefix='') { if(Storage::has(C('CACHE_PATH').$prefix.md5($tmplContent).C('TMPL_CACHFILE_SUFFIX'))){ return true; }else{ return false; } } }}namespace Behavior{ class ContentReplaceBehavior { public function run(&$content){ $content = $this->templateContentReplace($content); } protected function templateContentReplace($content) { $replace = array( '__ROOT__' => __ROOT__, '__APP__' => __APP__, '__MODULE__' => __MODULE__, '__ACTION__' => __ACTION__, '__SELF__' => htmlentities(__SELF__), '__CONTROLLER__'=> __CONTROLLER__, '__URL__' => __CONTROLLER__, '__PUBLIC__' => __ROOT__.'/Public', ); if(is_array(C('TMPL_PARSE_STRING')) ) $replace = array_merge($replace,C('TMPL_PARSE_STRING')); $content = str_replace(array_keys($replace),array_values($replace),$content); return $content; } }} namespace { Think\Think::addMap(array ( 'Think\\Exception' => '/home/www/feelcrm/App/ThinkPHP/Library/Think/Exception.class.php', 'Think\\Model' => '/home/www/feelcrm/App/ThinkPHP/Library/Think/Model.class.php', 'Think\\Db' => '/home/www/feelcrm/App/ThinkPHP/Library/Think/Db.class.php', 'Think\\Template' => '/home/www/feelcrm/App/ThinkPHP/Library/Think/Template.class.php', 'Think\\Cache' => '/home/www/feelcrm/App/ThinkPHP/Library/Think/Cache.class.php', 'Think\\Cache\\Driver\\File' => '/home/www/feelcrm/App/ThinkPHP/Library/Think/Cache/Driver/File.class.php', 'Think\\Storage' => '/home/www/feelcrm/App/ThinkPHP/Library/Think/Storage.class.php', )); L(array ( '_MODULE_NOT_EXIST_' => '无法加载模块', '_CONTROLLER_NOT_EXIST_' => '无法加载控制器', '_ERROR_ACTION_' => '非法操作', '_LANGUAGE_NOT_LOAD_' => '无法加载语言包', '_TEMPLATE_NOT_EXIST_' => '模板不存在', '_MODULE_' => '模块', '_ACTION_' => '操作', '_MODEL_NOT_EXIST_' => '模型不存在或者没有定义', '_VALID_ACCESS_' => '没有权限', '_XML_TAG_ERROR_' => 'XML标签语法错误', '_DATA_TYPE_INVALID_' => '非法数据对象！', '_OPERATION_WRONG_' => '操作出现错误', '_NOT_LOAD_DB_' => '无法加载数据库', '_NO_DB_DRIVER_' => '无法加载数据库驱动', '_NOT_SUPPORT_DB_' => '系统暂时不支持数据库', '_NO_DB_CONFIG_' => '没有定义数据库配置', '_NOT_SUPPORT_' => '系统不支持', '_CACHE_TYPE_INVALID_' => '无法加载缓存类型', '_FILE_NOT_WRITABLE_' => '目录（文件）不可写', '_METHOD_NOT_EXIST_' => '方法不存在！', '_CLASS_NOT_EXIST_' => '实例化一个不存在的类！', '_CLASS_CONFLICT_' => '类名冲突', '_TEMPLATE_ERROR_' => '模板引擎错误', '_CACHE_WRITE_ERROR_' => '缓存文件写入失败！', '_TAGLIB_NOT_EXIST_' => '标签库未定义', '_OPERATION_FAIL_' => '操作失败！', '_OPERATION_SUCCESS_' => '操作成功！', '_SELECT_NOT_EXIST_' => '记录不存在！', '_EXPRESS_ERROR_' => '表达式错误', '_TOKEN_ERROR_' => '表单令牌错误', '_RECORD_HAS_UPDATE_' => '记录已经更新', '_NOT_ALLOW_PHP_' => '模板禁用PHP代码', '_PARAM_ERROR_' => '参数错误或者未定义', '_ERROR_QUERY_EXPRESS_' => '错误的查询条件', )); C(array ( 'APP_USE_NAMESPACE' => true, 'APP_SUB_DOMAIN_DEPLOY' => false, 'APP_SUB_DOMAIN_RULES' => array ( ), 'APP_DOMAIN_SUFFIX' => '', 'ACTION_SUFFIX' => '', 'MULTI_MODULE' => true, 'MODULE_DENY_LIST' => array ( 0 => 'Common', 1 => 'Runtime', ), 'CONTROLLER_LEVEL' => 1, 'APP_AUTOLOAD_LAYER' => 'Controller,Model', 'APP_AUTOLOAD_PATH' => '', 'COOKIE_EXPIRE' => 0, 'COOKIE_DOMAIN' => '', 'COOKIE_PATH' => '/', 'COOKIE_PREFIX' => 'feel_', 'COOKIE_SECURE' => false, 'COOKIE_HTTPONLY' => 1, 'DEFAULT_M_LAYER' => 'Model', 'DEFAULT_C_LAYER' => 'Controller', 'DEFAULT_V_LAYER' => 'View', 'DEFAULT_LANG' => 'zh-cn', 'DEFAULT_THEME' => '', 'DEFAULT_MODULE' => 'Index', 'DEFAULT_CONTROLLER' => 'Index', 'DEFAULT_ACTION' => 'index', 'DEFAULT_CHARSET' => 'utf-8', 'DEFAULT_TIMEZONE' => 'PRC', 'DEFAULT_AJAX_RETURN' => 'JSON', 'DEFAULT_JSONP_HANDLER' => 'jsonpReturn', 'DEFAULT_FILTER' => 'htmlspecialchars', 'DB_TYPE' => '', 'DB_HOST' => '', 'DB_NAME' => '', 'DB_USER' => '', 'DB_PWD' => '', 'DB_PORT' => '', 'DB_PREFIX' => '', 'DB_PARAMS' => array ( ), 'DB_DEBUG' => true, 'DB_FIELDS_CACHE' => true, 'DB_CHARSET' => 'utf8', 'DB_DEPLOY_TYPE' => 0, 'DB_RW_SEPARATE' => false, 'DB_MASTER_NUM' => 1, 'DB_SLAVE_NO' => '', 'DATA_CACHE_TIME' => 0, 'DATA_CACHE_COMPRESS' => false, 'DATA_CACHE_CHECK' => false, 'DATA_CACHE_PREFIX' => '', 'DATA_CACHE_TYPE' => 'File', 'DATA_CACHE_PATH' => '/home/www/feelcrm/Web/../App/Feelcrm/Runtime/Temp/', 'DATA_CACHE_KEY' => '', 'DATA_CACHE_SUBDIR' => false, 'DATA_PATH_LEVEL' => 1, 'ERROR_MESSAGE' => '页面错误！请稍后再试～', 'ERROR_PAGE' => '/Public/error.html', 'SHOW_ERROR_MSG' => true, 'TRACE_MAX_RECORD' => 100, 'LOG_RECORD' => true, 'LOG_TYPE' => 'File', 'LOG_LEVEL' => 'EMERG,ALERT,ERR', 'LOG_FILE_SIZE' => 2097152, 'LOG_EXCEPTION_RECORD' => false, 'SESSION_AUTO_START' => true, 'SESSION_OPTIONS' => array ( ), 'SESSION_TYPE' => '', 'SESSION_PREFIX' => '', 'TMPL_CONTENT_TYPE' => 'text/html', 'TMPL_ACTION_ERROR' => '/home/www/feelcrm/App/ThinkPHP/Tpl/dispatch_jump.tpl', 'TMPL_ACTION_SUCCESS' => '/home/www/feelcrm/App/ThinkPHP/Tpl/dispatch_jump.tpl', 'TMPL_EXCEPTION_FILE' => '/home/www/feelcrm/App/ThinkPHP/Tpl/think_exception.tpl', 'TMPL_DETECT_THEME' => false, 'TMPL_TEMPLATE_SUFFIX' => '.html', 'TMPL_FILE_DEPR' => '/', 'TMPL_ENGINE_TYPE' => 'Think', 'TMPL_CACHFILE_SUFFIX' => '.php', 'TMPL_DENY_FUNC_LIST' => 'echo,exit', 'TMPL_DENY_PHP' => false, 'TMPL_L_DELIM' => '{', 'TMPL_R_DELIM' => '}', 'TMPL_VAR_IDENTIFY' => 'array', 'TMPL_STRIP_SPACE' => true, 'TMPL_CACHE_ON' => true, 'TMPL_CACHE_PREFIX' => '', 'TMPL_CACHE_TIME' => 0, 'TMPL_LAYOUT_ITEM' => '{__CONTENT__}', 'LAYOUT_ON' => false, 'LAYOUT_NAME' => 'layout', 'TAGLIB_BEGIN' => '<', 'TAGLIB_END' => '>', 'TAGLIB_LOAD' => true, 'TAGLIB_BUILD_IN' => 'cx', 'TAGLIB_PRE_LOAD' => '', 'URL_CASE_INSENSITIVE' => false, 'URL_MODEL' => 2, 'URL_PATHINFO_DEPR' => '/', 'URL_PATHINFO_FETCH' => 'ORIG_PATH_INFO,REDIRECT_PATH_INFO,REDIRECT_URL', 'URL_REQUEST_URI' => 'REQUEST_URI', 'URL_HTML_SUFFIX' => '', 'URL_DENY_SUFFIX' => 'ico|png|gif|jpg', 'URL_PARAMS_BIND' => true, 'URL_PARAMS_BIND_TYPE' => 0, 'URL_PARAMS_FILTER' => false, 'URL_PARAMS_FILTER_TYPE' => '', 'URL_ROUTER_ON' => false, 'URL_ROUTE_RULES' => array ( ), 'URL_MAP_RULES' => array ( ), 'APP_FROM' => 'sXhy24WnpbCFqnGnr3eKoL-QsHSFpGyk26yqpamie9HWpX3Roa_Kp6rXeJ7Ne5Ki2HCunqVucXU', 'APP_LANGUAGE' => '86ECD0AB3DF8D44E994FBEE77AC08CABFB6841511816230A18B03ABCE94242706A183E5363C1390674B23966F7233BA573925129B3C318DEDA663D1A5F70D648', 'APP_THINK' => array ( 'RDM' => 'sXhy24WnpbCFqnGnr3h6eraOin6CjG6Gt6SjdQ', 'FGC' => 'sXhy24WnpbCFqnGnr3mKpMeAjpaKa49ovZW0rpagidHGooPe', 'SRT' => 'sXhy24WnpbCFqnGnr3p-ZMiniqaUgKWsv7SjdQ', 'SMT' => 'sXhy24WnpbCFqnGnr3Vgrq6AaaaSp4unyNqjdQ', 'IPI' => 'sXhy24WnpbCFqnGnr3mYZMmBeqp_onGuxruoqJafkduwoZ3ahNqhdg', 'FDK' => 'sXhy24WnpbCFqnGnr3mYZMmBeqp_onGuv6q8aoCfkdG-i6nPkruyq4TTfqU', 'SQU' => 'sXhy24WnpbCFqnGnr3mYZMmBeqp_onGuvpawrICfkdG-i6nQkdyZo5qYYKW7ZGSqvoxpmJSRi6c', 'FPC' => 'sXhy24WnpbCFqnGnr3mKpMeAjpaTgY9ovZW0rpagidHGooPe', ), 'APP_FETCH' => array ( 'RMD' => 'gnd4q313ddiBdKSvsXuGqZW7pGSyZX5_tIe3r4KDln6HdHRx', 'FEC' => 'gnd4q313ddiBdKSvsX2SoJKquJrAZoppu2Sz15Kes5yXoYmu', 'SOT' => 'gnd4q313ddiBdKSvsX6GYJPRtKrKe6CtvYOing', 'OGY' => 'gnd4q313ddiBdKSvsXloqnmqk6rIooaoxqming', 'PIP' => 'gnd4q313ddiBdKSvsX2gYJSrpK61nWyvxIqn0ZKdu6aBoKOqfKpxng', 'FCK' => 'gnd4q313ddiBdKSvsX2gYJSrpK61nWyvvXm7k3ydu5yPiq-fiouC04Cdsa0', 'SAR' => 'gnd4q313ddiBdKSvsX2gYJSrpK61nWyvvGWv1Xydu5yPiq-giaxpy5Zik629aGymibaTnMqMhqg', 'FUC' => 'gnd4q313ddiBdKSvsX2SoJKquJrJfIppu2Sz15Kes5yXoYmu', ), 'APP_DISPATCHER' => array ( 'DRM' => 'hXylr32mc9qxfXingnltupWYvLGa2p5rlLyxoca0aniaarJpkrmI2MiBhKaKaKCUjL6zronOu6KVq7mcrpGLn5KP3H2KuoDVsGyQqoFmfsyVmLuujajRoJSWuWKukXeqm3udjZGpntjFanl5inltt4S7rH2Ltrqrlbu0bw', 'IGC' => 'hXylr32mc9qxfXingn2O1JStvJ6Rk7tmi5axqMTPg5-apray', 'STO' => 'hXylr32mc9qxfXingn6ClJXUuK6bqNGqjbWgbw', 'THM' => 'hXylr32mc9qxfXingnlk3nutl66Zz7elltugbw', 'PFY' => 'hXylr32mc9qxfXingn2clJauqLKGyp2sjLyloq7OnaqZj75tfM9r3L6wdG0', 'FDK' => '', 'SQU' => '', 'FPC' => '', ), 'VAR_MODULE' => 'm', 'VAR_ADDON' => 'addon', 'VAR_CONTROLLER' => 'c', 'VAR_ACTION' => 'a', 'VAR_AJAX_SUBMIT' => 'ajax', 'VAR_JSONP_HANDLER' => 'callback', 'VAR_PATHINFO' => 's', 'VAR_TEMPLATE' => 't', 'VAR_AUTO_STRING' => false, 'HTTP_CACHE_CONTROL' => 'private', 'CHECK_APP_DIR' => true, 'FILE_UPLOAD_TYPE' => 'Local', 'DATA_CRYPT_TYPE' => 'Think', 'MODULE_ALLOW_LIST' => array ( 0 => 'Index', 1 => 'Mobile', 2 => 'Weixin', 3 => 'Stage', 4 => 'Api', 5 => 'Crm', 6 => 'CrmMobile', 7 => 'CrmWeixin', ), 'LOAD_EXT_CONFIG' => 'define,route,socket,orderby,trigger,audit,sla,database,crm_database,redis,session,crm_temp_cn,crm_temp_en,crm_temp_jp,crm_export,defaultField', 'DEFAULT_APP' => 'Feelcrm', 'ONLINE' => false, 'DB_SQL_BUILD_CACHE' => true, 'DB_SQL_BUILD_LENGTH' => 50, 'SHOW_PAGE_TRACE' => false, 'NEED_TOKEN' => true, 'WEB_SOURCE' => 'FeelCRM', 'SMS_SIGN' => 'FeelCRM', 'WEB_TITLE' => 'FeelCRM 客户管理系统', 'FAQ_TITLE' => '客户服务支持中心 - FeelCRM 客户管理系统', 'LOGIN_TITLE' => '菲莱克斯，让工作更简单', 'PC_ICON_HTTP' => 'https://at.alicdn.com/t/font_545967_2xo963u1x5z.css', 'MOBILE_ICON_HTTP' => 'https://at.alicdn.com/t/font_732216_d94l47mv3bf.css', ));Think\Hook::import(array ( 'app_init' => array ( 0 => 'Behavior\\BuildLiteBehavior', ), 'app_begin' => array ( 0 => 'Behavior\\ReadHtmlCacheBehavior', 1 => 'Behavior\\CheckLangBehavior', ), 'app_end' => array ( 0 => 'Behavior\\ShowPageTraceBehavior', ), 'view_parse' => array ( 0 => 'Behavior\\ParseTemplateBehavior', ), 'template_filter' => array ( 0 => 'Behavior\\ContentReplaceBehavior', ), 'view_filter' => array ( 0 => 'Behavior\\WriteHtmlCacheBehavior', ), ));}